Assign Cell Array to singe variable

19 views (last 30 days)
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.

Accepted Answer

Walter Roberson
Walter Roberson on 31 Jul 2016
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));

More Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 30 Jul 2016
Edited: Azzi Abdelmalek on 30 Jul 2016
d={1 2 3}
Why do you want to create A1, A2 and A3 when you can access to any value in d?
Stephen23 on 31 Jul 2016
Edited: Stephen23 on 31 Jul 2016
"I couldnt find a way to do this with cell arrays"
Loop over the cell array, perform the calculation. Read this:

Sign in to comment.


Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!