MATLAB Answers

0

How can I insert a smaller ones matrix into a larger zeros matrix?

Asked by Trisha Katz on 17 Oct 2019
Latest activity Answered by Andrei Bobrov
on 17 Oct 2019
fullsizeoutput_4766.jpeg

  0 Comments

Sign in to comment.

2 Answers

Answer by Walter Roberson
on 17 Oct 2019

A(starting_row : ending_row, starting_column : ending_column) = constant_to_fill_with * ones(number_of_rows, number_of_columns);

  3 Comments

Hi, I am still getting an error...I entered this code:
A=zeros(6,8)
D=ones(2,2)
A(5:6,1:5)=D(1:2,1:2)
And am getting the following error:
Unable to perform assignment because the size of the left side is
2-by-5 and the size of the right side is 2-by-2.
How can I resolve this?
A = zeros(6,8)
D = ones(2,5)
A(5:6,1:5) = D

Sign in to comment.


Answer by Andrei Bobrov
on 17 Oct 2019

AA = [5:12;ones(5,1)*[0 8 8 8 0 5 5 5]]
AA(end-1:end,1:5) = 1;
AA(4,7) = 7;
eq7 = AA == 7;
le7 = AA <= 7;
gt7 = AA > 7;
number_of_values_eq7 = sum(eq7(:))
number_of_values_le7 = sum(le7(:))
number_of_values_gt7 = sum(gt7(:))

  0 Comments

Sign in to comment.