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)
Related
I'm using GUIDE to display a plot within an axis that contains two data sets: the original signal and the average of the signal, but for some reason it seems to only plot one.
The axis is designated as m_graph and the data sets are avg and signal, which both share time.
plot(handles.m_graph, time,signal)
hold on
plot(handles.m_graph, time, avg)
When I compile the program, only the average is plotted. It seems to skip over the original signal or reset the axis. I've tried plotting just the signal so I know the data is fine.
I feel like I am missing something, maybe the set function?
Sorry my reasoning was a bit wrong; it applies to the current selected axes (it does not parent to the Figure).
However, using axes(h) followed by hold on or just hold(h,'on') will either switch the focus to the axes then turn hold on or turn hold on for a specified axes, respectively.
I am workin on a some sort of System test wherein i have a set of readings in the form of a .mat file.
It has a structure in the .mat file with one field as Measurement. It has several Arrays(e.g air mass flow, velocity, carbon content) which further have fields like time and value.
From these, I Need to plot the velocity and the air mass flow against time. For that i wrote the following command which gave me the corresponding plots:
plot(Measurement.(Measurement.air_mass_flow.time),Measurement.air_mass_flow.value)
plot(Measurement.(Measurement.velocity.time),Measurement.velocity.value)
Now i Need to create a script in matlab wherein i can get both the curves one under the other i.e. on the same page. Can anyone help in the Approach i should procede with ?
ok now i will further extend my question.
I have two fields as velocity and acceleration. I Need to plot it on the same curve with grids on for the comparison. But the y axis for both are different.
the velocity y-axis is: (0:20:120), which should be displayed on the left side and the acceleration y-axis is: (0:2:12) which should be displayed on the right side.
i wrote the following code for this:
plot(Measurement.(Measurement.VehV_v.time),Measurement.VehV_v.value)
grid on
set(gca,'xtick',[0:500:2000])
set(gca,'ytick',[0:20:120])
hold on
plot(Measurement.(Measurement.accel_w.time),Measurement.accel_w.value)
grid on
set(gca,'xtick',[0:500:2000])
set(gca,'ytick',[0:2:12])
Do i Need to write a function for that as i am directly reading the values from the structure.
plotyy() also doesnt seem to work
But the axis are not matching and the graph for acceleration is very small. Could anyone help me out with this ?
I also want to add a Picture of the Graphs here but unfortunately there is some error here. I hope the question is clear without the Picture.
Yes you can use the subplot command, e.g.:
figure
subplot(1,2,1)
plot(Measurement(Measurement.air_mass_flow.time),Measurement.air_mass_flow.value)
subplot(1,2,2)
plot(Measurement.(Measurement.velocity.time),Measurement.velocity.value)
You can use help subplot on Matlab for further details or have a look at this:
https://www.dartmouth.edu/~rc/classes/matlab_graphics/Matlab-subplots.html
I need to interpolate scattered data on a model represented by a 3D surface in Matlab. I tried it using "scatteredInterpolant", but the results were quite bad. This function only allows to specify the query points but not the 'ConnectivityList' because internally it performs its own Delaunay triangulation from the specified point set. However, I perfectly know not only the points but also the 'ConnectivityList', so I can create a Matlab 'triangulation representation' using "triangulation".
So my question is the following. Is there any way to give a predefined 'triangulation' to "scatteredInterpolant"? If it is not possible, is there any other Maltab function or class able to perform data interpolation on a previously triangulated 3D surface instead of performing its own triangulation from the query points?
Can anyone tell me how to generate a 3D surface model like CAD in Matlab ?
1.Input: Input is a collection of points with (x,y,z) where surface is present for an object(I'm using this for a 3D scanner where my inputs are (x,y,z) of surface)
2.Points should be displayed as a surface using some smooth interpolation.
3.More like surface generation from data points.
Thanks you.
In order to plot surfaces, you can use patch function. However, you need along with the points the faces information. In patch a surface consists of polygons that is specified using 3 point, which is the face information.
1
Since it seems like you will be inputting discrete points located on the surface of the object, you will first want to create a Nonconvex Polygon based on the data using Matlab's boundary function.
https://www.mathworks.com/help/matlab/ref/boundary.html
You can then use the trimesh function to create the figure
This question shows the input data and what was produced using this method: How do I create a 3D polygon/mesh over data points?
For the function z= 10+pow((x-2),2)+pow((y+5),2), I want to represent in a 3D plot every value of z for each (x,y) pair , with a display delay before each new value of z (like a moving point).
The values for x,y are read from files.
I tried to modify Jacobs code from Creating a point moving along a graph in MATLAB, but I couldn't get it to work for my 2 variable function.
I would like a general solution, because I will also need this plotting for a N-variable function.
Have a look at the following question and see if it answers yours:
animate plot / trajectory in matlab / octave