How to plot multiple functions in same figure (subplot) in Simulink? - matlab

Similar to what we can do with the subplot command in MATLAB to have many plots in a single figure, How can I plot different graphs in same figure using Simulink?
Note:
I am not asking about multiplotting which I already know how to do that using vector concatenate + scope but it gives me overriding plots. I am unable to find a way that I could have a separate subplot for each function.
Any help?

Have multiple inputs for your scope (image shows right-click menu)
Show multiple plots from the layout menu (up to 16x16 plots) of the open scope
VoilĂ , subplots! As per the documentation, the first n traces will be shown in the first n subplots of the layout. Any traces which can't be shown individually will all be grouped within the last subplot.

Related

Arraging multiple 3D plots

I have created 6 3D plots that I need to include in a research paper. However, I need to all the plots in a grid.
I've been trying the function subplot but all my plots are combining instead of forming a grid. I have tried setting nrows to various numbers but it does not change the layout. Any ideas on how to fix this? Or other functions that may serve the same purpose?
Shows the function for 1/6 plots, then the subplot function. to the right is the output:

Issue getting gscatter to separate by group

I want to create an understeer plot from telemetry I have for a corner of a racing circuit. I am trying to plot 'GPS Speed' against 'Steering Angle' where group is the 'Run' (i.e WarmUp, ConstantSpeed, Endurance1 or Endurance2).
MATLAB code
The data I have is for several laps of the whole circuit so I have split it into the relevant data points for each lap. When I run the script, it does produce a scatter graph with all the data but it only displays the group of the last plot and applies the same colour to all:
Is there a way I can fix this? I wondered whether if I could import the specified columns from the csv file into a matrix first as I would then only require one gscatter plot to display everything I require.

limited number of items in the plot browser option in MATLAB

When dealing with figures including several plots, sometimes you want to select a number of plots. The way I usually do it is opening the plot browser in the view section and it mostly is good enough. As you can see in the following snapshot, the plot browser does not show more than a specific number of plots, and is saying and 89 more ...
How can I access the other 89 plots? Is there any setting that you can force MATLAB to show all the plots in the plot browser?
In the command line, you can use
plotList = findobj(get(gca,'Children'),'Type','Line')
This will give you a list of handles to all of your plots. You can perform actions on any of these plots. For example - changing the color of the second and fourth plots to red:
set(plotList([2,4]),'Color','r')
Removing the third and sixth plots:
delete(plotList([3,6]))

MATLAB: Plotting two different axes on one figure

The MATLAB surf plot below is essentially two plots plotted adjacent to each other. For clarity, I have included some code below used to prepare the plot:
band1 = horzcat(band1, eSurface2(:,:,1));
band2 = horzcat(band2, eSurface2(:,:,2));
surf(band2,'DisplayName','band2');
surf(band3,'DisplayName','band2');
I would like for the y axis numbering to restart at the start of the second graph. How do I go about doing that?
You can use the 'YTick' and 'YTickLabel' properties of the axis to control the ticks, this way you can make it start from zero for the second graph. It will require some trail and error to get it right. See the relevant doc here (you'll have to scroll all the way to the bottom of the page).
Take advantage of the following feature of 'YTickLabel': "If you do not specify enough text labels for all the tick marks, MATLAB uses all of the labels specified, then reuses the specified labels".

How to merge two figure files into a single file

This should be a problem with a trivial solution, but still I wasn't able to find one.
Say that I have 2 matlab figures fig1.fig, fig2.fig which I want to load and show in the same plotting window.
What should I do?
I mean, I am pretty sure that I can accomplish the task using some low(er) level graphic command which extracts contents from one image and put them in the second one, nonetheless I cannot believe that there is not any high level function (load fig2 on top of fig1) that does this...Comparing 2 plots (unfortunately already saved) is a very common task, I'd say.
Its not clear if you want to extract data from the figures and compare the data, or if you want to combine the plots from two figures into a single figure.
Here is how you combine two figures into one (if thats what you want to do)..
First load the figures:
fig1 = open('FigureFile1.fig');
fig2 = open('FigureFile2.fig');
Get the axes objects from the figures
ax1 = get(fig1, 'Children');
ax2 = get(fig2, 'Children');
Now copy the hangle graphics objects from ax2 to ax1. The loop isn't neccesary if your figures only have a single axes
for i = 1 : numel(ax2)
ax2Children = get(ax2(i),'Children');
copyobj(ax2Children, ax1(i));
end
Note This example assumes that your figures have the same nubmer of axes and that you want to copy objects from the first axes in the second figure to the first axes on the first figure. Its up to you to figure out the proper indexing if the axes indices aren't lined up.
The answer slayton gave is good. Here's another tip: If you have two plots opened in two separate Matlab figure windows, don't forget you can point-and-click copy the proper plots. Do this by clicking the arrow pointer in the Matlab figure window, and then clicking on the plotted line. Copy the (plotted line, textbox, etc...) object. Then, similarly select the axis in the other Matlab figure window and paste it.
I give this 'silly' solution because it has proven to be useful in in collaboration meetings. Point-and-click copying in front of someone (like your adviser) communicates exactly what curves are being compared, and it prevents you from having to fire up code in front of others.
You can also go to File in the menu, Generate Code, for each plots.
Then copy and paste both in the same mfile, with a "hold on" in between and changing details related to the appearance.
Then run the new m-file.