Drawing on a m-file via the command window; possible?
이전 댓글 표시
Hey, so I've created an m-file but there's far too many outputs that I don't need all the time for me to be happy with. However I'd like to be able to get their values without having to tweak the m-file and reruning it.
Example code (m-file);
a = 6 * 4
b = 1 * 9
Now that would obviously output to the command window;
a = 24
b = 9
However, let's say I have 100 equations like that. I naturally don't want them all outputting to the command window everytime I run the code so I'd suppress their outputs with semicolons.
However I might want to get the value of b from the command window, and having to unsupress that part of the code and rerunning is a bit of a flaf when the code may take a couple minutes to fully run.
I seem to recall having a simulink file that output to the command window and all I needed to do was go to the command window and type the output name to get that value in the command window (so in the above example I would simply type "a" into the command window to get the output "a = 24").
So I was wondering if there was something similiar that can be done in a m-file?
Sorry for the layout of this question by the way, struggling to try and explain what I wish to do! For the same reason it's been a nightmare trying to search for a solution!
댓글 수: 2
The longer I think about it, the less I understand the problem. Tying "a" in the command window seems to be the best solution already, when you want something like "a = 24". If clear is a problem, do not call it. Or are you talking about the difference between M-scripts and M-functions?
I do not think that there is a magic dwim command (do what I mean), such that you simply have to program the wanted output manually.
Stephen
2012년 7월 3일
채택된 답변
추가 답변 (1개)
Luffy
2012년 7월 3일
Yeah,you can do the similar think in a m-file as u did in your simulink file as long as you haven't typed clear in the command window.
Example:-
......
......
a = 6*4;
b = 1*9;
......
.......
Say the above was all in m-file and you run it and the variables are saved in workspace so you just need to type b in command window.
댓글 수: 5
TAB
2012년 7월 3일
Variables will be saved in the base workspace only if they are created in m-script (not function).
If your m-file is a function file, you need to save the variables in base workspace manually using evalin() or assignin().
Probably your m-file is a function file.
After creating variable 'a' in m-file save it to base workspace manually.
Example:
a=[10 20 30];
assignin('base','a',a);
After running your m-file, type
>> a
on command window.
Stephen
2012년 7월 3일
TAB
2012년 7월 3일
1. Yes, there are multiple workspaces in matlab, like Base workspace, Function workspace and Global workspace. assignin() function saves the variable into the target workpsace.
See
>>doc assignin
2. Unfortunately assignin() can save one variable at time. You can collect all your variable into a structure and save it to workspace in just one function call.
For example:
% These are the variables
a = 4;
b = 7;
c = 100;
% Collect them in one structure variable
Mystruct.a = a;
Mystruct.b = b;
Mystruct.c = c;
% Now save the structure
assignin('base','Mystruct',Mystruct);
Now on command window you can see them using
>> Mystruct.a
>> Mystruct.b
>> Mystruct.c
카테고리
도움말 센터 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!