How to extract data from a cell array?

77 ビュー (過去 30 日間)
Paolo Ottonelli
Paolo Ottonelli 2020 年 1 月 6 日
編集済み: Paolo Ottonelli 2020 年 1 月 6 日
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
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
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 件のコメント
KSSV
KSSV 2020 年 1 月 6 日
There is no requirement to do this.
Guillaume
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 ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by