How do I label a plot as an object?

2 views (last 30 days)
pudje
pudje on 20 Jul 2016
Edited: Thorsten on 20 Jul 2016
I have a very long script, and I want to include code to plat multiple graphs. But, I want to only see individual plots after I 'call' it from the command window. How do I do this?
Initially, I drew subplots, but they always are plotted when I run the script, even if I put a ';' at the end of the lines of code.
I tried:
PLOT1 = plot(time, temp);
xlabel({'Time','(minutes)'});
ylabel({'Temperature','(°C)'});
But this didnt work. I would also like to be able to label the axis as shown above.
Thanks!

Answers (1)

Thorsten
Thorsten on 20 Jul 2016
Edited: Thorsten on 20 Jul 2016
You can add a pause after each plot
plot(time, temp)
xlabel({'Time','(minutes)'});
ylabel({'Temperature','(°C)'});
pause
plot(time2, temp2)
xlabel({'Time','(minutes)'});
ylabel({'Temperature','(°C)'});
Then you have to press a key to see the next plot.
Your label commands are fine.
The ; after plot just suppresses the output of the handle PLOT1, but not the plot.
If you don't want the plot, just remove the line, or put it in comment, or use something like
do_plot = true; % true or false
if do_plot
plot(time, temp)
end
if do_plot
plot(time2, temp2)
end
You could also overwrite the plot function with clf, e.g., in case you do not want any plots. Then you do not have to surround your plot commands with "if do_plot... end"; but this is kind of a hack, I guess:
if do_plot
clear plot % restore original plot command
else
plot = @(varargin) clf;
end
plot(time, temp)
plot(time2, temp2)

Community Treasure Hunt

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

Start Hunting!