How to plot arrays of different lengths?

10 次查看(过去 30 天)
Hello,
I exported data from a separate DAQ system to a .mat file. The DAQ system measured flow and differential pressure (DP) over the same time interval. The .mat file produced four data points of different lengths; flow(832750x1), flow_time(832750x1), DP(166550x1) and DP_time(166550x1).
I am able to plot flow and DP vs. time with separate y axes, but it makes it difficult to read. Is there any way to plot flow vs. DP? Thanks,

采纳的回答

Star Strider
Star Strider 2019-1-28
I would use the interp1 (link) function to interpolate one vector in terms of the other vector’s time.
Example —
DP_in_flow_time = interp1(DP_time, DP, flow_time, 'linear','extrap'); % Expresses ‘DP’ As A Function Of ‘flow_time’
figure
plot(flow_time, flow)
hold on
plot(flow_time, DP_in_flow_time)
hold off
NOTE — This is UNTESTED CODE. It should work, however I cannot test it without the data.
  2 个评论
TC
TC 2019-1-28
Thanks! The interp1 function worked. I did make one change, though.
The code above produces a similar graph as plotyy, except with only one axis rather than two. It produces two lines and plots them vs. time.
I was trying to create a graph with only one line to see a trend (when flow increases, DP increases, etc.) between the two. To do so, all I did was chage the code to:
DP_in_flow_time = interp1(DP_time, DP, flow_time, 'linear','extrap'); % Expresses ‘DP’ As A Function Of ‘flow_time’
figure
plot(flow, DP_in_flow_time);
Thanks, again!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by