Replacing a portion of matrix in cell with value of another matrix
1 view (last 30 days)
Show older comments
Hi, I have some problems in creating:
A cell eg : A = {[100x70double], [50x120], [7x20]} However, I want to replace the value of a portion from each array of cell A from another array. The replacement size is [2x3] where the value is B= [1.1 1.2 1.3;2.1 2.2 2.3;]
I'm currently trying this:
% code
for i = 1:size(A,1)
for j = 1:size(A,2)
A {i,j} (1:4,1:7) = B
end
end
But i've got "Subscripted assignment dimension mismatch" error.
Thank you in advance.
0 Comments
Accepted Answer
KSSV
on 2 Nov 2016
Edited: KSSV
on 2 Nov 2016
It should be:
for i = 1:size(A,1)
for j = 1:size(A,2)
A {i,j} (1:2,1:3) = B;
end
end
The indices which you specify shall cover 2X3. 1:4,1:7 makes a 4x7 matrix.
3 Comments
KSSV
on 2 Nov 2016
Edited: KSSV
on 2 Nov 2016
That code works perfect in my pc. Copy your full code here what you have tried?
clc; clear al;
A = {rand(100,70), rand(50,120), rand(7,20)} ; % a random data
B= [1.1 1.2 1.3;2.1 2.2 2.3];
% code
for i = 1:size(A,1)
for j = 1:size(A,2)
A {i,j} (1:2,1:3) = B;
end
end
More Answers (0)
See Also
Categories
Find more on Matrix Indexing 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!