0

I have an m-file with a big (working) structure. After lots of effort I've found a way to update some of structs with fprint etc. I got the file saved and everything seems good when it´s saved but I want to use the struct further down in the function.

I can run the m-file (that stores the struct) by run(FileName) Actor=ans;

But it doesn't work all the time and seems like a bad way of doing it.. If i write: Actor=IndataActor %The name of the indatafile is IndataActor.. It works fine (Actor got the struct) But I want to use the variable "FileName" Actor=FileName

Actor just got the name of the FileName (Actor='IndataActor')

Any suggestions?

Suever
  • 64,497
  • 14
  • 82
  • 101
axel_ande
  • 359
  • 1
  • 4
  • 20
  • Are you saying that you generate m-files using fprint? Bad practice. m-files ought to be code, which is written by humans. If you want to save data, then build it in memory and then, well, save() it. – Wolfgang Kuehn Feb 26 '14 at 21:49
  • No, I made several changing in the struct in the m-file with fprint.. So the m-file is saved and all good, but I want to assign the struct to a variable now. – axel_ande Feb 27 '14 at 09:52
  • I assume that with struct you mean _MATLAB data type struct_. And such a struct you don't change with fprint. So I guess you have to show some code so that people understand what you are trying to achieve. – Wolfgang Kuehn Feb 27 '14 at 14:44

1 Answers1

0

Well the struct is saved in an m-file (as a function)...

function [ Actor ] = IndataActorsLund3

%Actor 1
Actor{1}.Name='Räddningstjänsten Syd';
Actor{1}.ExpertNames={'Saknas?'};
Actor{1}.Units={'Saknas?'};
Actor{1}.Titles={'Saknas?'};
Actor{1}.NbrGoals=5;
Actor{1}.Goals={'Trygghet för medborgare', 'Bränder och andra olyckor ska minska','Öka kunskapen angående olyckshantering och riskmedvetenheten', 'Påbörja insats inom 10 minture i 90% av prioriterade olyckor', 'Bryta negativ trend vid insats inom 15min'};
Actor{1}.NbrActivities=6;
Actor{1}.Activities={'Tillsyn, remishantering','Informationsinsatser', 'Internutbildning', 'Externutbildning', 'Skadeavhjälpande insats', 'Olycksutredning','','','',''}; 
Actor{1}.MatrixActGoals=[...
3   4   3   4   3;
5   3   4   2   2;
3   3   1   4   5;
4   3   4   2   2;
5   1   1   5   5;
3   3   2   3   3];
Actor{1}.NbrInfluencingFlows=1;
Actor{1}.InfFlowType(1)=19;
Actor{1}.InfFlowMatrix{1}=[...
0   0   0   0   0   0   0;
0   0   0   0   0   0   0;
0   0   0   0   0   0   0;
0   0   0   0   0.4 0.6 1;
0   0   0   0   0.2 0.5 1;
0   0   0   0   0   0   0];
Actor{1}.NbrDependentFlows=4;
Actor{1}.DepFlowType(1)=1;
Actor{1}.DepFlowMatrix{1}=[...
0   0   0   0   0   0   0;
0   0   0   0   0   0   0;
0   0   0   0   0   0   0;
0   0   0   0.1 0.3 0.5 0.7;
0   0   0   0.6 0.8 0.9 1;
0   0   0   0   0   0   0];
.... (and about 1000 more rows)
end

Than I have created a GUI (with GUIDE) to add and change data within the struct. So I read in the file and do changes in the file with several different fprint commands. And struct gets saved in the m-file as well that is already taken care of. Now I don´t know the best way to assign the struct to a variable.

axel_ande
  • 359
  • 1
  • 4
  • 20