How to plot Data from a table filled with strings?

12 vues (au cours des 30 derniers jours)
Dominik Kümpflein
Dominik Kümpflein le 23 Juil 2020
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 commentaires
Stephen23
Stephen23 le 23 Juil 2020
Just use str2double on the cell array (this is recommended rather than str2num):
Dominik Kümpflein
Dominik Kümpflein le 23 Juil 2020
I will! Thank you, Stephen!

Connectez-vous pour commenter.

Réponse acceptée

Neuropragmatist
Neuropragmatist le 23 Juil 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.
  1 commentaire
Dominik Kümpflein
Dominik Kümpflein le 23 Juil 2020
That's exactly what I was looking for!
Thank you so much!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by