2
votes

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.

1
Your question is not clear. A subplot? On the same plot? Two stacked axes? - excaza
Either use hold on before plotting the second plot, or use the same plot command: plot(x1,y1,x2,y2). This corresponds to the second case in the comment of @excaza. - Andras Deak
thanks for your valuable suggestions but the Problem is that i am reading data from a mat file which contains a structure. - Aakash Sehgal

1 Answers

3
votes

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