How to extract and replace from small matrix into big matrix without zeros. here is the code examples:
Show older comments
A = round(abs(randn(10,10)*100));
B = zeros(5,5);
for i = 1:5
for j = 1:5
if(i>1 && i<5 && j>1 && j<5)
B(i,j) = round(abs(randn(1)*100));
end
end
end
C = B>0==1;
A(4:8,3:7) = B; % This is not a solution
disp(A);
%error
A(4:8,3:7) = B(C); % This will be an array, not a matrix
Current answers:
A =
78 28 55 24 132 15 211 30 5 95
106 115 42 18 13 230 72 90 77 35
177 115 36 24 144 275 28 63 79 160
42 67 0 0 0 0 0 7 141 53
105 67 0 130 101 79 0 19 53 85
65 40 0 12 55 96 0 29 193 134
32 67 0 163 76 119 0 99 18 250
177 58 0 0 0 0 0 39 24 17
151 78 104 84 23 113 38 19 90 35
16 106 91 254 110 8 43 28 79 72
Note: zeros should be not there surounding it.
Accepted Answer
More Answers (0)
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!