Create Matrix using only zeros and ones

조회 수: 235 (최근 30일)
lamiae hmimou
lamiae hmimou 2020년 5월 16일
댓글: Walter Roberson 2021년 8월 31일
please how can i create this matrix using only the two commands "zeros" and "ones"
1 0 1 0
1 0 1 0
1 0 1 0
1 0 1 0
and this one :
0 0 0 1
0 0 0 1
0 0 0 1
1 1 1 1
  댓글 수: 3
lamiae hmimou
lamiae hmimou 2020년 5월 17일
i found out how to do it ! thanks for the hint it's a good method
M VENKATESH
M VENKATESH 2021년 8월 31일
How

댓글을 달려면 로그인하십시오.

답변 (2개)

William Alberg
William Alberg 2020년 5월 16일
편집: William Alberg 2020년 5월 16일
This should do it for the first matrix
A = zeros(4,4);
A(:,1) = 1; % set column 1 to 1
A(:,3) = 1; % set column 3 to 1
disp(A)
Im sure that you can use this example to do it for the second example
  댓글 수: 1
lamiae hmimou
lamiae hmimou 2020년 5월 16일
thank you so much , that helped ! i'll use the same method to solve the other ones .. Thanks again

댓글을 달려면 로그인하십시오.


DGM
DGM 2021년 8월 31일
편집: DGM 2021년 8월 31일
How about an example using concatenation only. No arithmetic composition or array indexing.
e = ones(2);
c = zeros(3,2);
n = ones(1,2);
l = zeros(1,2);
m = ones(2,6);
s = zeros(11,2);
f = zeros(2,6);
result = [s [f; [[e; c] [c; n; l] [e; c]]; m; f] s]
result = 11×10
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0
imshow(result)
  댓글 수: 5
M VENKATESH
M VENKATESH 2021년 8월 31일
Can u please sol this . Using the zeros and ones commands create a 3 x 5 matrix in which the first second, and fifth columns are 0s, and the third and fourth columns are 1s.
Walter Roberson
Walter Roberson 2021년 8월 31일
hint:
A = [zeros(8,1), ones(8,1), zeros(8,1)]
A = 8×3
0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by