Matrix with ones and zeros
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ang Vas
am 5 Feb. 2020
Kommentiert: the cyclist
am 6 Feb. 2020
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 Kommentare
Adam
am 5 Feb. 2020
What do you mean by all the combinations? Can you give an example? The result would seem to be bigger than a 3x3 matrix
Akzeptierte Antwort
the cyclist
am 5 Feb. 2020
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 Kommentare
the cyclist
am 6 Feb. 2020
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!