How to plot arrays of different lengths?

10 Ansichten (letzte 30 Tage)
TC
TC am 28 Jan. 2019
Kommentiert: Star Strider am 28 Jan. 2019
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,

Akzeptierte Antwort

Star Strider
Star Strider am 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 Kommentare
TC
TC am 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!
Star Strider
Star Strider am 28 Jan. 2019
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by