Is it possible to link axes of Simulink scopes? - matlab

In Matlab, it is possible to link axes of different figures using linkaxes. If you zoom in one figure, the corresponding figures will be zoomed in in the same way.
I wondered if something similar was possible with Simulink scopes. It would be handy if all scopes would rescale if you manually zoom in one scope.
(An alternative would of course be to export the data to the workspace, plot it in figures and use linkaxes.)
Edit
Extending the question: would it be possible to link axes of Matlab figures and Simulink scopes?

Simulink Scope blocks are just (fancy) MATLAB figures, so most things you can do in MATLAB you can do to a figure window.
In this case, you want to do something like
% Ensure the scopes of interest are open, then
% find the handle to all of them
hscopes = findall(0,'Tag','SIMULINK_SIMSCOPE_FIGURE');
% find the handles to all axes on the scopes
ha = findall(hscopes,'Type','Axes');
% link them
linkaxes(ha);
Obviously you need to do a little more work if you only want to link specific axes.
The procedure to link figures and scopes is similar.

Related

Matlab skipping plots (uncertainty)

I have a sequence of finding fits for data (cd to folder, read and fit the data) and subsequently plotting them in a loop.
I observe that few plots are done incorrectly, skipped and added in subsequent plots. A four second pause between each plots seems to solve this issue.
I assume everything is sequential in Matlab, meaning subsequent commands wait until current command is finished. I believe this is not the way happening now. I believe using pause is not the best solution. Can someone provide a fix for this?
A set of subsequent plots without the pause (solid line is a fit of datapoints on the fly):
The same plots with pause of 4 seconds:
subplot, and most other functions that generate graphics objects, provide a handle to the generated graphics object that you can use to address the object explicitly with functions like plot.
If an explicit axis handle is not provided to a plotting function, it will use the current axes, which can very often lead to issues like these. So much so that it's caveated in the documentation:
User interaction can change the current axes or chart. It is better to assign the axes or chart to a variable when you create it instead of relying on gca.
So rather than doing:
axes
plot(1:10)
You should do the following:
ax = axes;
plot(ax, 1:10)

Linking plotted data with color and size sources in MATLAB

This question is related to the question posted here, in which I outline a problem I'm facing regarding rapid visualization of 3D scatter plotted data in MATLAB during a simulation. (Sample code and data are also provided there.)
As an alternative to setting the XData, YData, ZData, SizeData, and CData properties of a 3D scatter plot in MATLAB, I'm wondering if it's possible to have all of their corresponding sources be dynamically linked to points that are 3D scatter plotted. The linked values would be queued into a buffer and plotted periodically (say, every 0.5 s). From what I understand, the sources are refreshed in the background, so plots with linked data would not slow down the simulation. From what I see in the documentation, only XDataSource, YDataSource, and ZDataSource are specified. Is dynamically linking the size and color data sources also possible, and if not, is there a simple workaround?
As a reminder, I'm using MATLAB R2016a on Windows 7.
Is dynamically linking the size and color data sources also possible, and if not, is there a simple workaround?
Yes, it is possible using the similarly named properties
SizeDataSource
CDataSource
These properties are set to the string names of the variables you want linked for updating. Then, with linking on, subsequent updates to these named variables will be reflected in your plots ever 1/2 second or so (at the fastest).
But, there is a big caveat here with your specific example.
The xxxxSource fields are typically initialized at the outset, when a graphic handle is created. This would be in your initial scatter3 calls.
The issue is that you have eight separate scatter plot handles, each referencing the same variable(s), but with different indexes. That is, you are updating the indices into these variables to produce your images.
A brute force way to use parameter linking here would be to create eight different variable names and link each to its corresponding scatter plot handle.
I think the cleaner solution is to use a timer callback to update things on a set time interval.

multiple eyediagrams on a single figure in MATLAB

Is there a way to have multiple eyediagrams on a single figure in MATLAB. I want to do something like this:
figure;
subplot(311);
eyediagram(x1, ....);
subplot(312);<br>
eyediagram(x2, ....);
subplot(313);
eyediagram(x3, ....);
Unfortunately each call to eyediagram creates its own plot. I already tried to plot multiple eyediagram and copy them individually to another figure but I was wondering if there is a better/cleaner way to do this.
Thanks!
From the documentation:
Note: You cannot use hold on to plot multiple signals in the same figure.
Based on that statement, and the fact that you can only specify a figure handle to eyediagram (see below) and not an axes handle, this is not possible apart from manually copying the plot objects as you have stated (likely using copyobj).
Specifying a Figure
eyediagram(x,n,period,offset,plotstring,h) is the same as the syntax above, except that the eye diagram is in the figure whose handle is h, rather than in a new figure. h must be a handle to a figure that eyediagram previously generated.

How to specify which axes to plot in a GUI

I am new to GUI. But I have two axes in GUIDE GUI and wish to specify the one to plot a figure, but I can't find handles.axe1 anywhere. Can anyone help me with this?
Since you built your GUI with GUIDE you can easily access the Tag property of each axes in the property inspector.
Once you know the tag of each axes, you can choose where to plot stuff using the first argument of plot:
plot(TagofAxes,x,y)
or using imshow, using the Parent property:
imshow(YourImage,'Parent',TagofAxes)
and so on.

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.