I want to create an 1,k cell of m,m matrices. I have some trouble trying to initialize it. My first idea was to do this
myCell = cell{1,K};
for k = 1:K
myCell{1,k} = eye(m);
end
But it seems like such ugly way to initialize it. There have to be a better way?
A solution with even fewer function calls:
[myCell{1:k}] = deal(eye(m));
Here's a very simple REPMAT solution:
myCell = repmat({eye(m)},1,K);
This simply creates one cell with eye(m)
in it, then replicates that cell K
times.
Try this:
myCell = mat2cell(repmat(eye(m),[1 k]),[m],repmat(m,1,k))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With