How to plot variables from many m files(script files) in Mainfile.m(script file)

1 Ansicht (letzte 30 Tage)
I have Many M files say `
GAdeferrableload.m
GAnondeferrableload.m
GAinterruptibleload.m
GAnoninterruptibleload.m
GAmustrunload.m
WDO_SG_Code_PL_test1mdeferrableload.m
WDO_SG_Code_PL_test1mnondeferrableload.m
WDO_SG_Code_PL_test1minterreuptibleload.m
WDO_SG_Code_PL_test1mnoninterreuptibleload.m
WDO_SG_Code_PL_test1mmustrunload.m
GA_WDO_DeferrableLoad.m
GA_WDO_NonDeferrableLoad.m
GA_WDO_InterruptibleLoad.m
GA_WDONonInterruptibleLoad.m
GA_WDOMustRunLoad.m
and one `Mainfile.m file which are all script files and I want to plot variables of all M files in `Mainfile.m.Please any suggestion?I want to do it via .mat files.My problem is still not solved please i need more comments and help.
  1 Kommentar
Stephen23
Stephen23 am 6 Mär. 2016
Bearbeitet: Stephen23 am 6 Mär. 2016
Duplicate of all of these:
dpb made a comment on the newsreader thread, which is worth quoting here:
"It appears your primary problem is one of data organization. Having 500 separate variables in each of some 15 separate scripts and expecting to be able to keep them all straight at one time just sounds essentially impossible (as it seems you're finding out)."
@Zafar Iqbal: your problem is your data organization. You need to organize (and store) your data much better than this. By choosing to store your data in such a an unstructured way you have made your own life very difficult. Basically the more thought you put into creating efficient data organization the easier it is to write code to solve your task.
Repeatedly asking the same question is also not going to fix your poor data organization.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Adam
Adam am 4 Mär. 2016
Just have each file save its workspace to a matfile if that is what you want.
Then load the matfiles in the one in which you want to plot them.
I would recommend using functions and moving data around in a more controlled manner rather than a load of scripts whose workspaces are not at all self-contained, but I guess it is too late for that so simplest approach seems to be what you already suggest.
e.g.
save( 'GAdeferrableload.mat' )
in GAdeferrableload.m if you literally want to save every single variable. Otherwise you can specify the exact variables you want to save as subsequent arguments to the save function.
  2 Kommentare
Zafar Iqbal
Zafar Iqbal am 5 Mär. 2016
Bearbeitet: Stephen23 am 6 Mär. 2016
thanks Adam but i already done that i made all above files as .mat files(with all variables) and then save and load in mainfile.m as save Gadeferrable.mat, load Gadeferrable.mat and when i run Mainfile.m it gave error undefined variable or function and i have 15 .mat files in mainfile.m but when i execute Mainfile.m only one or two of above m files variables come to work space and not all i observe usually the last file executed in mainfile.m variables load into workspace,each of the above m file run individually ok and no error and i checked many times all variables in 15 m files have different names,i try global variable and got similar error then try varargin and varargout with function and got such error,you recommended function can you gave me example of function considering the above files and mainfile.m,mainfile.m is attached.
screenshots of my code folder is also attached.
Adam
Adam am 5 Mär. 2016
If you just load .mat file contents straight into the workspace then any variables with the same name as those in the workspace will obviously overwrite the existing ones.
You should use the syntax to load into a struct and/or ideally deal with each file's contents one at a time before loading the next.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Debugging and Analysis finden Sie in Help Center und File Exchange

Tags

Noch keine Tags eingegeben.

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by