How to combine different figures in a Matlab script?

孤者浪人 提交于 2019-12-24 05:15:47

问题


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:


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



来源:https://stackoverflow.com/questions/33632474/how-to-combine-different-figures-in-a-matlab-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!