필터 지우기
필터 지우기

Matrix with ones and zeros

조회 수: 2 (최근 30일)
Ang Vas
Ang Vas 2020년 2월 5일
댓글: the cyclist 2020년 2월 6일
Hi everybody I apologize for my ignorance but I want your help. I want to create a ones(3) matrix from the zeros(3) matrix by having all the combinations with 0 and 1.
  댓글 수: 2
Adam
Adam 2020년 2월 5일
What do you mean by all the combinations? Can you give an example? The result would seem to be bigger than a 3x3 matrix
Ang Vas
Ang Vas 2020년 2월 6일
What I want is every time that I change a 0 with a 1 to know how many matrixes I will have and which ones when I change two 0 with two 1 to have the matrices and so on until change all 0 with 1where the final matrix it will be [111;111;111]

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

채택된 답변

the cyclist
the cyclist 2020년 2월 5일
Do you mean that you want every possible combination of 3x3 matrix filled with 0 or 1? The following is pretty obfuscated code, but it is fast and easy:
A = reshape((dec2bin(0:2^9-1) - '0')',3,3,[]);
A is a 3x3x512 array, where each "slice" in dimension 3 is one possible matrix.
  댓글 수: 4
Ang Vas
Ang Vas 2020년 2월 6일
Ok, sorry but I have just started to learn Matlab and I don't know much of it. Can I do that with an m file?
the cyclist
the cyclist 2020년 2월 6일
I'm not sure I understand what you are asking. What I posted is a line of MATLAB code, and you can put it in an m file like any other MATLAB code. It is no different from putting
B = 3 + 6;
in an m file.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by