how to generate binary matrix of mxnxp

Hi.......
This is the integer matrix which is generated by using integer values
A=randi(4,5,5,2)-1
can any one help me in generating the above integer matrix in to binary matirx having (0's and 1's) of dimension mxnxp
thanks in advance.

Antworten (1)

Guillaume
Guillaume am 24 Jan. 2019

0 Stimmen

Your question is not very clear. The code you show generates a matrix of integer between 0 and 3 (included), not 0 and 1, because the first input you pass to randi is 4 (and you subtract 1) from the result. If you weren't aware that the first input is the upper bound of the integers generated by randi, perhaps you should look at the documentation.
To generate a binary matrix of size MxNxP:
A = randi([0 1], M, N, P)

4 Kommentare

ABDUL
ABDUL am 24 Jan. 2019
Bearbeitet: ABDUL am 24 Jan. 2019
No doubt i agree with your answer, i have an integer matrix consistning numbers like
a=randi([0 3],5,5,2)
a(:,:,1) =
1 3 3 0 0
2 2 0 2 3
1 3 0 0 3
2 0 1 3 1
1 1 2 0 0
a(:,:,2) =
3 0 2 2 0
0 2 1 0 0
3 1 2 3 2
0 1 3 1 1
3 1 2 3 1
I want to convert the above matrix in binary form for mxnxp dimensions and again back to integer form
Guillaume
Guillaume am 24 Jan. 2019
What is the binary form (in matlab syntax) of your a matrix?
ABDUL
ABDUL am 26 Jan. 2019
binary form means matrix consisting of 0's and 1's for eg 1 is represented as 01 in dibit , if u have to reoresent it 3 bits it will be 001 and so on ...
I know what the binary representation of a numbe is. What I have no idea is what you call the binary form of a matrix. So once again, what is the binary form of your example matrix.
binaryform = cat(3, ... %is the binary form 3d as well. 4d maybe?
[? ? ? ? ? %how many columns?
? ? ? ? ? %how many rows?
], %how many pages?
[? ? ? ? ?
? ? ? ? ?])

Melden Sie sich an, um zu kommentieren.

Gefragt:

am 24 Jan. 2019

Kommentiert:

am 26 Jan. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by