Plotting values from a double array based on information from a cell array
2 views (last 30 days)
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:
'49108.015' 'max-pressure-evac 60.0'
'65837.015' 'max-pressure-evac 60.0'
'72410.015' 'max-pressure-evac 60.0'
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.
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])
>> figure, plot(data.timesec, data.p2Torr), grid on, zoom on
>> text(28979.015, Vq(1), 'hold');
>> text(39780.015, Vq(2), 'hold-end');