Help with calling string elements to form matrix

3 次查看(过去 30 天)
i have a very large table of data (sample numbers with different pressures, temps and compositions) and its much easier to have that data stored in a single string, so that it can be seen that column 30 relates to information on ....
as there are 6 variables i need to plot for 5 different pressures for all the data, id rather not create 30 short lived and unnecessary variables, where there now is no information linked about the sample number, and simply be able to call elements from the string to my plots.
for example, lets say the original string S is:
S={'D' 'P' 'T' 'X';
'D1' 1 3 5;
'D2' 2 4 6};
i would like to be able to do something like:
plot(S(2,:),S(1,:)) or T=S(2:3,3)
i have tried str2double(S(2:3,3)), but that returns 2 NaN values
i have tried T=S{2:3,3}, but for some reason that only returns the first value (in this case T=3 as a 1x1)
str2num returns an error: Requires string or character array input, and str2mat returns an error: Error using char; Inputs must be character arrays.
any help or a different way to go about it would be much appreciated
  1 个评论
Stephen23
Stephen23 2014-10-1
编辑:Stephen23 2014-10-1
Are you sure that you have a table of data? Or is this data contained in some file? Your example shows a cell array , so please clarify in exactly what form your data is stored, as it is not clear in your explanation where the data is, and this is important to know how to handle it best (importing, indexing, plotting,...).
If your data is in an external file, then you can import is using one of the text-file reading tools . If it is data already in MATLAB, then storing it as strings would be huge waste of memory and makes processing extremely slow.
Resolving the best way to plot the data will be much much easier when your data is stored and accessed in a suitable manner, so it is worth resolving this topic first.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by