I have an .m file with store variables, how do I call it in a script to get the stored variables?
1 view (last 30 days)
Show older comments
I have an .m file that looks like this:
%Information
%Information
%Information
C = [1 1 0 0 0;
1 0 1 0 1;
0 1 1 1 0;
0 0 0 1 1];
Sx = [1 0 0;
0 0 0;
0 0 0;
0 0 0];
Sy = [0 1 0;
0 0 1;
0 0 0;
0 0 0]
X = [0 1 .5 1 .5];
Y = [0 0 1 1 .3];
L = [0 0 0 0 0 0 1 0];
I am trying to save each line of "info" as a separate string per line to be displayed later, and then call the variables, C, Sx, Sy, X, Y, L in a script. How do I do this?
0 Comments
Accepted Answer
Image Analyst
on 9 Apr 2012
For example in your other m-file script:
C_copy = C;
Sx_copy = Sx;
plot(X, Y);
regionprops(L);
and so on. Note, that works because the first script leaves those variables in the base workspace. If it were a function, they'd be gone once the function gets done running.
2 Comments
Image Analyst
on 9 Apr 2012
You can use uigetfile() to have the user select the file. Don't make them know the name of the file in advance and have to type it in - that's cruel.
You can get comments (I assume that's what you mean by "notes") by opening the file with fopen(), reading line by line with fgetl() and using strfind() to look for percent symbols that are not enclosed within a string (look for single quotes), and take the rest of the line after the percent symbol. You may also want to take a look at lookfor().
More Answers (0)
See Also
Categories
Find more on Variables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!