# how to reshape the matrix

2 vues (au cours des 30 derniers jours)
Shehab Tarek le 18 Mai 2020
i have matrix =001001001111011101111;
and i want to convert it to
001
001
001
111
011
101
111
i know reshape function
matrix=reshape(matrix,[],3);
but it not get the answer which i need
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

David Hill le 18 Mai 2020
m =[0 0 1 0 0 1 0 0 1 1 1 1 0 1 1 1 0 1 1 1 1];
a=reshape(m,3,[])';
##### 5 commentairesAfficher 3 commentaires plus anciensMasquer 3 commentaires plus anciens
Shehab Tarek le 18 Mai 2020
good
but how to make the first line from double matrix to M=[0,0,1,......];
Stephen23 le 18 Mai 2020
M=[0,0,1,......];
is also a double matrix. Try it and see:
>> M=[0,0,1];
>> class(M)
ans = double
So instead of a double array you want a double array? In any case, reshape does not change the array type, so whatever type array you have at the start is what you will get at the end.

Connectez-vous pour commenter.

### Plus de réponses (1)

Sai Bhargav Avula le 18 Mai 2020
Modifié(e) : Sai Bhargav Avula le 18 Mai 2020
Hi,
Try the following code
convert matrix to char
matrix ='001001001111011101111';
matrix=reshape(matrix,[],3);
Hope this helps!
##### 7 commentairesAfficher 5 commentaires plus anciensMasquer 5 commentaires plus anciens
Shehab Tarek le 18 Mai 2020
Modifié(e) : Shehab Tarek le 18 Mai 2020
Sai Bhargav Avula le 18 Mai 2020
Modifié(e) : Sai Bhargav Avula le 18 Mai 2020
Thanks for the explanation and clearing my confusion Stephen Cobeldick,
I was thinking more about matrix being a single value(matrix = 001001001111011101111) and not an array( [0 0 1 .....]) and output to be a single colum vector (7*1) and overlooked the expected result .
matrix ='001001001111011101111';
matrix= string(reshape(matrix,3,[])');

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Logical dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by