Assign Cell Array to singe variable

For a cell array or length n. I want to assign each cell to variables named A1, A2, etc with a loop. For example:
>> whos d
Name Size Bytes Class Attributes
d 1x3 39720 cell
>> [A1 A2 A3] = d{1:end};
I would like to do this with a loop to accomadate a cell array of any length.
Thanks

 採用された回答

Walter Roberson
Walter Roberson 2016 年 7 月 31 日

2 投票

num_item = numel(d);
for K = 1 : num_item
subplot(1, num_item, K);
C2 = d{K}(:,2) ./ TheScalar;
C3 = d{K}(:,3) ./ TheScalar;
plot(C2, C3);
title(sprintf('plot #%d', K));
end

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 7 月 30 日
編集済み: Azzi Abdelmalek 2016 年 7 月 30 日

0 投票

d={1 2 3}
Why do you want to create A1, A2 and A3 when you can access to any value in d?
d{1}
d{2}
d{3}

2 件のコメント

Zekeftw
Zekeftw 2016 年 7 月 31 日
Each of the values of d are 500x3 doubles. For example:
I need to divide the second and third column of each d by a scalar. Then plot the second vs third column of each d.
I couldnt find a way to do this with cell arrays. So I wanted to store the data in an array. To perform the calculation.
Stephen23
Stephen23 2016 年 7 月 31 日
編集済み: Stephen23 2016 年 7 月 31 日
"I couldnt find a way to do this with cell arrays"
Loop over the cell array, perform the calculation. Read this:

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2016 年 7 月 30 日

編集済み:

2019 年 6 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by