How to plot arrays of different lengths?

10 views (last 30 days)
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,

Accepted Answer

Star Strider
Star Strider on 28 Jan 2019
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 Comments
TC
TC on 28 Jan 2019
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!

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!