I have an .m file with store variables, how do I call it in a script to get the stored variables?
조회 수: 2 (최근 30일)
이전 댓글 표시
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
채택된 답변
Image Analyst
2012년 4월 9일
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
Image Analyst
2012년 4월 9일
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().
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!