How to plot Data from a table filled with strings?
20 次查看(过去 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 个评论
Stephen23
2020-7-23
Just use str2double on the cell array (this is recommended rather than str2num):
采纳的回答
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!