How to plot variables from a table?

조회 수: 39 (최근 30일)
Tomaszzz
Tomaszzz 2021년 11월 17일
댓글: Tomaszzz 2021년 11월 17일
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?

채택된 답변

dpb
dpb 2021년 11월 17일
>> 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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by