MATLAB Answers

How to plot Data from a table filled with strings?

15 ビュー (過去 30 日間)
Hello Guys,
I have a problem with plotting Data from a table I get via readtable from a xls-File. The first line of the table is the Measurement-Unit and the following ones are the Measurement-Values. Looking like this:
Now, I am trying to plot the LogTime at the X-Axis and the TalpipeCO2 as Y-Axis. I tried it by getting rid of the first row and converting the table/cell to a matrice using cell2mat. So I can get plottable values using str2num after it. That works for all the Measurement-Signals, but not for the LogTime, saying:
p = app.requestedPlotData.LogTime.(1)(2:end,:)
p =
2×1 cell array
{'0' }
{'0.1'}
K>> cell2mat(p)
Error using cat
Dimensions of arrays being concatenated are not consistent.
Error in cell2mat (line 83)
m{n} = cat(1,c{:,n});
Is there a way to plot the data from my tables as they are? Is the conversion from strings to doubles necessary or is there a better way I can't see?
If necessary: The Cell-type in the Excel-File is "Standard"
Code I use for the Data import:
obj.Conti = readtable(fullfile(path, file),'Sheet','Continuous');
And then I extract one specific column (like TailpipeCO2) outside the function depending on User-Input.
I really appreciate your help. I hope I provides enough information for you to understand my problem

  2 件のコメント

Stephen Cobeldick
Stephen Cobeldick 2020 年 7 月 23 日
Just use str2double on the cell array (this is recommended rather than str2num):
Dominik Kümpflein
Dominik Kümpflein 2020 年 7 月 23 日
I will! Thank you, Stephen!

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

採用された回答

Neuropragmatist
Neuropragmatist 2020 年 7 月 23 日
I think your problem is just that the cell array contains strings of different lengths, you can try converting them to numbers inside the cell array first; for example:
p = app.requestedPlotData.LogTime.(1)(2:end,:)
c = cell2mat( cellfun(@str2num, p, 'un', 0) )
Thanks,
NP.

  1 件のコメント

Dominik Kümpflein
Dominik Kümpflein 2020 年 7 月 23 日
That's exactly what I was looking for!
Thank you so much!

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

その他の回答 (0 件)

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by