Plotting values from a double array based on information from a cell array

10 views (last 30 days)
Hello,
I have two sets of data. One is a cell array in which the first column is times and the second column is key words. It takes on the following form:
'28979.015' 'hold'
'39780.015' 'hold-end'
'39910.015' 'hold'
'49108.015' 'max-pressure-evac 60.0'
'49169.015' 'evac-end'
'50711.015' 'hold-end'
'50841.015' 'hold'
'58642.015' 'hold-end'
'58772.015' 'hold'
'65837.015' 'max-pressure-evac 60.0'
'65898.015' 'evac-end'
'65973.015' 'hold-end'
'66103.015' 'hold'
'72410.015' 'max-pressure-evac 60.0'
'72471.015' 'evac-end'
'73304.015' 'hold-end'
These time values correspond to specific points in time of the data that I would like to plot in the second much larger matrix (166088x3). The data file is too large to attach but takes the form below:
0 0.0515833570000000 0.00455798800000000
2 0.0589201300000000 0.00452135800000000
4 0.0726283130000000 0.00436905700000000
6 0.0712768020000000 0.00442689300000000
8 0.0448258020000000 0.00440375800000000
10 0.0697322180000000 0.00448665700000000
12 0.0494595540000000 0.00448858500000000
14 0.0266769400000000 0.00443074900000000
16 0.0342067870000000 0.00447123400000000
18 0.0602716410000000 0.00441339800000000
Here, the first column is time, the second column is upstream pressure, and the third column is downstream pressure. I would like to plot time vs. downstream pressure (the first and third columns). What I am struggling with is plotting the correct values against each other. Basically I want to plot a line for the data between every two keywords. For example, a line between 'hold' and 'hold-end' for the first two rows of the cell array followed by a line for ' hold' and 'max-pressure-evac 60.0' followed by a line for 'evac-end' and 'hold-end' etc. as you move down the cell array. Any help would be greatly welcomed. Thank you.
  4 Comments
dpb
dpb on 24 Jan 2022
Your associated data file doesn't have that much precision for time, at least in what you've shown us. How do you want to match times, nearest prior/after, interpolate, ...?
It would be best to attach a dataset that can be used as is; you can select the range of the large file that brackets the wanted times...
Justin Rosenthal
Justin Rosenthal on 24 Jan 2022
Here is the actual file. Nearest after the first data point and nearest prior the last data point would be great. Hopefully this helps.

Sign in to comment.

Answers (2)

Benjamin Thompson
Benjamin Thompson on 24 Jan 2022
Using interp1 for table lookup and the text function it looks like this is coming pretty close to what you describe. I attached my import function for loading your CSV data, just auto generated using the MATLAB data import tool. Then you can also use the output of interp1 to plot the lines.
>> Vq = interp1(data.timesec, data.p2Torr, [28979.015 39780.015])
Vq =
0.0520 8.9650
>> figure, plot(data.timesec, data.p2Torr), grid on, zoom on
>> text(28979.015, Vq(1), 'hold');
>> text(39780.015, Vq(2), 'hold-end');
>>
  1 Comment
Justin Rosenthal
Justin Rosenthal on 24 Jan 2022
Hello Benjamin. Thank you for the input. So this is the graph that I am able to make as well. What I ideally want are 8 different lines on the same plot. They should not be continuous with each other.

Sign in to comment.


David Hill
David Hill on 24 Jan 2022
idx=strcmp(yourCell(:,2),'hold')|strcmp(yourCell(:,2),'hold-end');
plot(yourMatrix(idx,1),yourMatrix(idx,3));
  1 Comment
Justin Rosenthal
Justin Rosenthal on 27 Jan 2022
I think I didn't explain myself correctly as the problem is very difficult to describe in text. However your help is still greatly appreciated.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!