Reputation: 55
I am relatively new to matlab, and I was wondering if there was a simpler way to do the following:
Given mycellarray = {[1 2 3 4] [5 6 7 8] [9 10 11 12] [13 14 15 16]}
, I would like to assign each matrix inside mycellarray
to a separate variable. Is there any faster/better/shorter way to do it than this?
a = cell2mat(mycellarray(1,1))
b = cell2mat(mycellarray(1,2))
c = cell2mat(mycellarray(1,3))
d = cell2mat(mycellarray(1,4))
Thanks in advance!
Upvotes: 2
Views: 70
Reputation: 3194
Here a short example on how to do what you want with the MATLAB function deal
.
a = {[1 2 3] [4 5 6] [7 8 9]}
[aa bb cc] = deal(a{:})
Upvotes: 1
Reputation: 36710
[a,b,c,d]=mycellarray{:}
The {:}
makes a comma seperated list of the cell array, which an be assigned to individual variables.
relevant documentation pages:
Upvotes: 4