Matlab figures: Which format to reuse in Matlab? - matlab

I have two scripts that produce some plots. I want to reuse those figures in another script, which will create subplots with the plots from the first script on the left-hand side, and plots from the second script on the right-hand side.
I tried to save the figures from the first scripts in tiff and then loading them in the last script, but the result is blurry (probably due to resizing). Which format should I use to save the figures with the first scripts?

Related

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.

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

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.

Save MATLAB subplot as PDF

In my project i have 10 subplot commands. I want the subplots to be saved in PDF format. I tried by using saveas(gcf,'Trial_Plot.pdf') command at the end of all these subplot commands, then i get a PDF with all the subplots in a crowded manner (with large margins in the PDF).
How can I avoid this? Is it possible to create the PDF for the first subplot command, then for the rest the subplots are appended to that same PDF? Is this appending method possible ?

How to apply different line styles automatically to arrays in when plotting Matlab

Is it possible to make Matlab to apply different line styles automatically as it does with colors when told to plot a higher dimension array?
For example:
plot(t,X1(:,4:6))
Creates a plot with three lines of different color. Can Matlab do the same thing with line styles? Even if it is something like:
plot(t,X1(:,4:6),{':','-','-*'})
I'd rather not have to go and call a plot command for each 1D array individually and assign a line style there if I can help it. I'm working with legacy code that has a ton of calls without line styles already, each plotting a half dozen lines. It would take a while to do manually and I have to think Matlab can do something smarter
Thanks!
You can do it in one command, but you still have to assign the style separately.
plot(t,X1(:,4),':',t,X1(:,5),'-',t,X1(:,6),'-*')
The other option you have is to write your own function that goes through a for loop and plots each one with different styles.

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.