How to plot Data from a table filled with strings?

조회 수: 10 (최근 30일)
Dominik Kümpflein
Dominik Kümpflein 2020년 7월 23일
댓글: Dominik Kümpflein 2020년 7월 23일
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
Stephen23
Stephen23 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개)

카테고리

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

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by