How to combine different figures in a Matlab script? - matlab

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

Related

MATLAB: Plotting 2 figures into 2 axes, in a GUI

I have 2 figures generated that show a 3D cube, and one that shows a net. I have associate these with two axes in a GUI using this:
axes(handles.cube);
axes(handles.net);
What I do not understand is how to transfer the figure into each one.
This is probably very simple, I'm very new and very inept with this piece of software- so any advice is greatly appreciated.
I am not sure if this is what you are looking for, but you can use subplot for plotting two different axes in one window, if this is what you desire:
https://de.mathworks.com/help/matlab/examples/displaying-multiple-plots-in-a-single-figure.html

Smooth lofted surface with Matlab isosurface

I'm trying to generate a 3D structure from a set of 2D cross sections in Matlab- in my case it's a wing that I've optimized the structure for. For the simple example I have two cross sections that are not identical. They can be seen here.
Now I want to do a loft between the surfaces and put caps on the ends, which I do with isosurface and isocaps, respectively. Since I don't want the vague contours, I include a threshold
threshold=0.6;
% loft
fv=isosurface(xq,yq,zq,vq,threshold);
%lids
fvc=isocaps(xq,yq,zq,vq,threshold);
fvc.faces = fvc.faces + size(fv.vertices,1); %re-numbering
%structure with nodes and elements of surface+lids
fall.faces = [fv.faces; fvc.faces];
fall.vertices = [fv.vertices; fvc.vertices];
Now, if I call patch to plot it: pall=patch(fall), it looks like this.
Can anybody tell me why the outer surface is not smooth? And even better, can anyone provide a solution to the issue?
Is it simply that the spacing between the cross sections is too large?
EDIT: Just to clarify. The edge in the middle on the 3d plot is not wanted. I have no idea why it is there. As this is a wing, it's supposed to simply connect the 2d cross sections. There is no data in that region, only at z=2.5m and z=7.5m, as indicated by the cross sections figure.

Getting a cross-section from power-spectrum

I am currently trying to use spectral-methods to analyse topographic landscapes.
When i FFT the landscape and plot the power-spectrum. From the power-spectrum an orientation of the structures in the landscape can be found.
2D power-spectrum:-
In this power-spectrum, i would like to make a cross-section.
This is easy when the peak amplitude orientation is along the x or y-axis.
But for this area (and others), this is not the case.
Cross-section from another area - orientated along the y-axis:-
My problem is i want to make a cross-section along the peaks in 1, and i just cant seem to figure it out how.
If anyone could point me towards some solution for this. Been stuck here for a couple of days now.
Edit 1
I would like the cross-section, to be a line along the peak orientation.
Edit 2
Improved the first image to show where i want my cross-section
My solution was, as GameOfThrows suggested:
Pick 2 (or more) points on the orientation i want
used Least squares on the points to create the line
Setup a meshgrid for the interpolation.
Use the interp2 function on the new line.
define a proper axis for the section
In my final cross section i ended up having multiple lines in it, that way i was sure to hit the max amplitudes.
i was a little with the answer to my question, but i have been busy :)
You can use ginput built-in matlab function to store 2 (x,y) coordinates of your power spectrum and then use this values to delimit a profile to be interpolated.

MATLAB: Digitizing a plot with multiple variables and implementing the data

I have 8 plots which I want to implement in my Matlab code. These plots originate from several research papers, hence, I need to digitize them first in order to be able to use them.
An example of a plot is shown below:
This is basically a surface plot with three different variables. I know how to digitize a regular plot with just X and Y coordinates. However, how would one digitize a graph like this? I am quite unsure, hence, the question.
Also, If I would be able to obtain the data from this plot. How would you be able to utilize it in your code? Maybe with some interpolation and extrapolation between the given data points?
Any tips regarding this topic are welcome.
Thanks in advance
Here is what I would suggest:
Read the image in Matlab using imread.
Manually find the pixel position of the left bottom corner and the upper right corner
Using these pixels values and the real numerical value, it is simple to determine the x and y value of every pixel. I suggest you use meshgrid.
Knowing that the curves are in black, then remove every non-black pixel from the image, which leaves you only with the curves and the numbers.
Then use the function bwareaopen to remove the small objects (the numbers). Don't forget to invert the image to remove the black instead of the white.
Finally, by using point #3 and the result of point #6, you can manually extract the data of the graph. It won't be easy, but it will be feasible.
You will need the data for the three variables in order to create a plot in Matlab, which you can get either from the previous research or by estimating and interpolating values from the plot. Once you get the data though, there are two functions that you can use to make surface plots, surface and surf, surf is pretty much the same as surface but includes shading.
For interpolation and extrapolation it sounds like you might want to check out 2D interpolation, interp2. The interp2 function can also do extrapolation as well.
You should read the documentation for these functions and then post back with specific problems if you have any.

get the y coordinates by clicking on the plot in matlab

I am trying to get the y coordinates on a xy plot by clicking on the plot. This is very similar to the function ginput which will generate a cursor and by clicking on the plot you can get the x and y coordinates where the cursor is placed. However, for my particular purpose, I want to have a line cross the figure instead of cursor as a guide of determining the right y value to use. Is there any function in matlab can do this? If not, what is the way to do it? Any help is greatly appreciated.
I don't believe there is a pre-packaged function for that, but you can do it using the strategies described in this video tutorial from Doug Hull, with slight modifications.