How to extract data from a cell array?
조회 수: 56 (최근 30일)
이전 댓글 표시
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
Stephen23
2020년 1월 6일
"..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.
채택된 답변
KSSV
2020년 1월 6일
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
Guillaume
2020년 1월 6일
"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?
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!