How can I assign values to elements with same index from multiple cells?
Ältere Kommentare anzeigen
I have a cell array with the same-size matrix in each cell, say,
a = cell(2);
[a{:}]=deal(rand(2));
and I want to change the first element of the matrix in each cell to values 1,2,3 and 4 respectively. Something equivalent to
a{:}(1,1) = 1:4;
would be ideal however this syntax doesn't work. Is there any other way?
2 Kommentare
Walter Roberson
am 7 Jan. 2016
I don't think this can be done with this kind of syntax.
Stephen23
am 7 Jan. 2016
The best solution is to avoid cell arrays and use multi-dimensional numeric arrays. then this task is trivial to achieve. See Guillaume's answer for an example of how to do this.
Akzeptierte Antwort
Weitere Antworten (2)
Stalin Samuel
am 7 Jan. 2016
[r c] = size(a);
val = 0;
for n1 = 1:r
for n2 = 1:c
val = val+1;
a{n1,n2}(1,1) = val;
end
end
Hamid Arbabi
am 7 Jan. 2016
0 Stimmen
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!