Assign Cell Array to singe variable
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Zekeftw
am 30 Jul. 2016
Bearbeitet: Stephen23
am 19 Jun. 2019
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};
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/155285/image.png)
I would like to do this with a loop to accomadate a cell array of any length.
Thanks
1 Kommentar
Akzeptierte Antwort
Walter Roberson
am 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));
end
0 Kommentare
Weitere Antworten (1)
Azzi Abdelmalek
am 30 Jul. 2016
Bearbeitet: Azzi Abdelmalek
am 30 Jul. 2016
This is not recommended. Read this http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F
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}
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!