How to extract data from a cell array?

66 views (last 30 days)
Hello, it's the first time that i use arrays and I have a series of 3x1 cell arrays, each of them has 3 cells vith a differet numbers of numerical data. I want to use for loop or while loop in order to ectract the three cells and convert them into different 3 vectors:
C={[2.24;2.28;2.31], [0.99;1.44;1.44;1.44;1.44;2.12;2.25;2.48;3.61], [1.86;1.89;1.89;1.89;1.89;1.89;1.89]};
for j=1:length(C)
x(j)=C{j};
end
at the end I should have:
x1=[2.24;2.28;2.31]
x2=[0.99;1.44;1.44;1.44;1.44;2.12;2.25;2.48;3.61]
x3= [1.86;1.89;1.89;1.89;1.89;1.89;1.89]
  1 Comment
Stephen23
Stephen23 on 6 Jan 2020
"..at the end I need to have: x1... x2...x3"
Is there a particular reason why you cannot just use indexing to access your data?
Using numbered variables is certainly possible, but it will force you into writing slow, complex, obfuscated, buggy code that is hard to debug. Read this to know why:
Indexing is simple, neat, easy to debug, and very effiicent. Unlike what you are trying to do.

Sign in to comment.

Accepted Answer

KSSV
KSSV on 6 Jan 2020
Already you have the cells in your desired way.
You can access them using C{1} , C{2}, C{3} .
You need to store them again into X1, X2, X3.
  3 Comments
KSSV
KSSV on 6 Jan 2020
There is no requirement to do this.
Guillaume
Guillaume on 6 Jan 2020
"but i need to convert my array"
Why? As Stephen pointed out in his comment to your question, this will complicate your code for no useful benefit as far as we can tell. So please explain this need.
Why can't you write C{1} wherever you were going to write X1?

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!