如何在Matlab脚本中组合不同的图形? [英] How to combine different figures in a Matlab script?
问题描述
我正在从事某种系统测试,其中我具有一组.mat文件形式的读数. 它在.mat文件中具有一个结构,其中一个字段为Measurement.它具有多个数组(例如空气质量流量,速度,碳含量),还具有诸如时间和值之类的字段. 从这些,我需要绘制速度和空气流量随时间变化的曲线图.为此,我编写了以下命令,给了我相应的图:
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:
- 绘制图(Measurement.(Measurement.air_mass_flow.time),Measurement.air_mass_flow.value)
- 绘图(Measurement.(Measurement.velocity.time),Measurement.velocity.value)
现在,我需要在matlab中创建一个脚本,在该脚本中,我可以将两条曲线一条放在另一条下面,即在同一页面上.任何人都可以帮助我继续进行的方法吗?
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.
-
我有两个字段,分别是速度和加速度.我需要将其绘制在同一条曲线上并进行网格比较.但是两者的y轴都不同.
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.
速度y轴为(0:20:120),应显示在左侧,加速度y轴为:(0:2:12),其应显示在右侧.
我为此编写了以下代码:
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])
我是否需要为此编写函数,因为我直接从结构中读取值.
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.
但是轴不匹配,加速度曲线非常小.有人可以帮我吗?
我也想在此处添加图形图片,但是不幸的是这里存在一些错误.我希望没有图片,问题会很清楚.
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.
推荐答案
是的,您可以使用subplot命令,例如:
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)
您可以在Matlab上使用帮助子图获取更多详细信息,或查看以下内容: https://www.dartmouth.edu/~rc/classes/matlab_graphics /Matlab-subplots.html
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
这篇关于如何在Matlab脚本中组合不同的图形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!