Help with calling string elements to form matrix

1 view (last 30 days)
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 Comment
Stephen23
Stephen23 on 1 Oct 2014
Edited: Stephen23 on 1 Oct 2014
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.

Sign in to comment.

Answers (0)

Categories

Find more on Data Type Identification in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!