Reading data out of a character cell array - all values, and save those in a new variable
11 views (last 30 days)
Show older comments
Dear Matlab-Gods out there!
My situation: I created a server to access data from my database. So my data is automatically stored in a cell array. (6 lines with information like time, name, values of my measurement, ...) Now I'd like to visualize these measurements, but first of all of course read out the line of data including those.
Structure: My data is stored in a 6x1400 cell array. I got different data types, from double to char inside of it. For example in line 5 I can find all my measurement values, saved as char.
My approaches so far: If I'd like to access data out of a cell array I try it as followed.
datensatz{5,:};
Typing this into the command window, everything works out fine: I get all the input of row 5. Though if I write it into the editor, all I get for
mw=datensatz{5,:};
messwert=str2num(mw);
is the very first value of my data. Actually I got more than a 1000 values in there. Might this be a problem too?
Can anyone give me a hint on how to proceed? I'd really appreciate any comment!
Best regards.
2 Comments
Accepted Answer
More Answers (1)
jrbbrt
on 13 Jun 2018
Edited: jrbbrt
on 13 Jun 2018
1 Comment
Stephen23
on 13 Jun 2018
Edited: Stephen23
on 13 Jun 2018
"Means MATLAB can't typically take the content from these cells I'd like to read out and place them into a single array"
Taking the contents out of the cell array would give you a whole lot of separate char vectors, basically as separate variables. You could join them into one char array, but this is not likely to be very useful for you. In any case, this is what you are doing now:
[m1 m2 m3]=datensatz{5,1:3};
Why do you want to separate the contents of the cell array into three separate variables? In general, keeping data together makes it much easier to work with. You could simply get the part of the cell array that you are interested in (which is thus just one array):
C = datensatz(5,1:3);
Note the parentheses: you should read about the different ways to index cell arrays:
You indicate that the fifth row contains char vectors, so keeping them in a cell array is quite reasonable, if you only want a subset of datensatz. Or perhaps you could convert the cell array to string.
If that row contains char vectors that represent numeric values, then you can easily convert these to a numeric array: see my answer to know how simple this is.
See Also
Categories
Find more on Data Type Conversion 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!