How to plot variables from a table?

44 ビュー (過去 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.
  1 件のコメント
Tomaszzz
Tomaszzz 2021 年 11 月 17 日
Thank you

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by