How to plot Data from a table filled with strings?

20 Ansichten (letzte 30 Tage)
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 Kommentare
Stephen23
Stephen23 am 23 Jul. 2020
Just use str2double on the cell array (this is recommended rather than str2num):
Dominik Kümpflein
Dominik Kümpflein am 23 Jul. 2020
I will! Thank you, Stephen!

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Neuropragmatist
Neuropragmatist am 23 Jul. 2020
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.

Weitere Antworten (0)

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by