Is there XY Graph block in Xcos - matlab

In Simulink, there is an XY Graph block. Is there a similar block in Xcos?
I work in Xcos. When I use CScope in my model, I get a graph showing either s-t (coordinate-time) or v-t (speed-time) dependency. But I need my s and v to be the axes of the graph (I need to show how speed depends on the coordinate). In Simulink, I should use the XY Graph block. How can I do it in Xcos?

Use the CSCOPXY block (in the Sinks Palette).

Related

Plotting position data from Simulink in MatLab

I have constructed a simulator in Simulink that simulates the position of an object. I want to visualize the X-Y position of this object in a matlab figure.
I exported the X-Y data from Simulink to matlab using the To Workspace block. From this I get an x and y time series data out.x_pos and out.y_pos. I can plot them against time with
plot(out.x_pos)
But the following does not work to get an X-Y plot
plot(out.x_pos, out.y_pos)
What is the best way to produce this X-Y plot?
Since no one helped me, I will present what I came up with after eventually reaching the right pages on the MATLAB documentation.
The To Workspace block exports the data as a timeseries object. This object has the values of the signal as a property called Data. To access the property one writes <object>.Data, so to obtain the desired X-Y plot one writes
plot(out.x_pos.Data, out.y_pos.Data)

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.

Is it possible to link axes of Simulink scopes?

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.

Mesh Generation in MATLAB

Is there any subroutine, in MATLAB, that takes in a list of points, and return me a good mesh that I can use to show to my colleagues, such as this?
Actually, all I need is just a simple 2D mesh generator that takes in a series of X, Y coordinates (that defines the boundary of the area), and give me back a list of elements that can mesh that area well. I can do the rest by using MATLAB command to interpolate the Z value.
Edit : I am not interested to use MATLAB to produce the above looking plot. I am interested in using a MATLAB library to obtain a list of elements so that when I plot those element myself (not in MATLAB itself; but in my own C# program), I can obtain this meshed surface.
PS: I know there is this DistMesh, but I am looking for something simpler - something built-in direct in MATLAB perhaps. And no, meshgrid is not mesh generation.
It sounds like you want to create a finite element mesh, starting with a set of points defining a boundary of a region and then generating a triangular mesh that creates more points within that region. I don't think there's a "simple" solution for this problem.
The closest "built-in" solution would probably be the Partial Differential Equation Toolbox, specifically some of the Geometry Algorithms like INITMESH and REFINEMESH.
The link you gave to DistMesh appears to be another good solution. There are also a few submissions on the MathWorks File Exchange that you could take a look at:
MESH2D by Darren Engwirda
Finite Element Toolbox 2.1 by Rasmus Anthin
That picture looks exactly like the one from the griddata documentation. The example in there looks like what you want.
SFTOOL will easily make the picture that you show.
A thin-plate spline, e.g., TPAPS, should also do the job.
I think the user-created 'gridfit' is the best I've come across for a single surface, much better/prettier than griddata.
Mesh generation as in Delaunay Triangulation + Steiner Points? There is a builtin Delaunay function in MATLAB.
If your surface is the z=f(x,y) form you can use:
http://www.advancedmcode.org/how-to-plot-a-coloured-surface-from-3d-scatter.html
If your surface is concave look for surface reconstruction on the same website.