问题
I am working 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,acceleration, carbon content) which further have fields like time and value.
I Need to plot different field valus against the respective times.
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?
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.
I think so that i Need to use
plotyy()
function but I am unable to implement it.can anyone help me with this ?
回答1:
Yes you want to use plotyy.
If you want to set your scales to particular values you should create hangles for the axis when creating the plot e.g.
[AX,H1,H2] = plotyy(time, velocity, time, acceleration);
Where AX has two elements for the first and second axis which you can set e.g.
set(AX(1),'ytick',[0:20:120])
H1 and H2 are used to set the style etc. of the appropriate data.
来源:https://stackoverflow.com/questions/33651674/superimposing-two-plots-with-different-axes