Reading data out of a character cell array - all values, and save those in a new variable

24 次查看(过去 30 天)
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 个评论
jrbbrt
jrbbrt 2018-6-13
Thanks! So I'm going to use this command instead.
Do you have any ideas why I only get the first value of my data instead of the whole line out of my cell array which I tried to requested via my code?

请先登录,再进行评论。

采纳的回答

Stephen23
Stephen23 2018-6-13
编辑:Stephen23 2018-6-13
If that row of the cell array contains numeric values stored in char vectors, then you can easily convert these to numeric:
vec = str2double(datensatz(5,:))
  1 个评论
jrbbrt
jrbbrt 2018-6-13
Indeed - super simple! Thank you so much for helping me Stephen!! Somehow I am still mixing up those little details so easily, and I guess that's why I had a hard time on this. Thanks, again :)

请先登录,再进行评论。

更多回答(1 个)

jrbbrt
jrbbrt 2018-6-13
编辑:jrbbrt 2018-6-13
So I think I found the answer:
[m1 m2 m3]=datensatz{5,1:3};
Using this line of code works for me. Means MATLAB can't typically take the content from these cells I'd like to read out and place them into a single array. So I guess one has to assign to each element separately.
... what is super inconvenient in my situation (with that much columns of data!) :(
  1 个评论
Stephen23
Stephen23 2018-6-13
编辑:Stephen23 2018-6-13
"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.

请先登录,再进行评论。

类别

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