
How to plot variables from a table?
30 views (last 30 days)
Show older comments
Hi all,
I have a table with variables (as depicted below and attached).

I want to plot the varibales highlighted red (for example). I do this in this way.
% convert the variables to categorical array (because this allows me to plot the variables)
data.time = categorical(data.time);
data.l_avgP = categorical(data.l_avgP);
% plot the variables
figure('color','w');
plot(data.time,data.l_avgP,'b');
ylabel('Average pressure (kPa)');
xlabel ('Time stamp (hours)');
box off;
axis tight;
Which results in this:

Apart from the visible issues, this is very slow (40 sec to produce a plot). Could you please suggest a more effiicient way to do this?
0 Comments
Accepted Answer
dpb
on 17 Nov 2021
>> load Xsensor_ID002_SN01_XT001_XSN.mat
>> data.time=duration(strrep(data.time,'"',''),'InputFormat','hh:mm:ss.SSS');
>> data.l_avgP=str2double(strrep(data.l_avgP,'"',''));
>> tic,plot(data.time,data.l_avgP,'b-'),toc
Elapsed time is 0.087834 seconds.
>>
results in

You need to go back to reading in the table to begin with -- somehow you managed to create the table as strings in cells instead of converting to native values on input.
Without the input data file, we can't tell why/how that happened, but readtable should bring in the data as numeric for everything other than the time which should be a duration.
More Answers (0)
See Also
Categories
Find more on Annotations 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!