Drawing on a m-file via the command window; possible?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Jan
il 3 Lug 2012
Modificato: Jan
il 3 Lug 2012
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.
Risposta accettata
Ilham Hardy
il 3 Lug 2012
You might want check this:
disp(a)
HTH,IH
3 Commenti
Ilham Hardy
il 3 Lug 2012
The poster asks,
"So I was wondering if there was something similiar that can be done in a m-file?"
There you go,
disp
Più risposte (1)
Luffy
il 3 Lug 2012
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 Commenti
TAB
il 3 Lug 2012
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
Vedere anche
Categorie
Scopri di più su Environment and Settings in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!