how to reshape the matrix

조회 수: 4 (최근 30일)
Shehab Tarek
Shehab Tarek 2020년 5월 18일
편집: Sai Bhargav Avula 2020년 5월 18일
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

채택된 답변

David Hill
David Hill 2020년 5월 18일
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
Shehab Tarek
Shehab Tarek 2020년 5월 18일
good
but how to make the first line from double matrix to M=[0,0,1,......];
Stephen23
Stephen23 2020년 5월 18일
Your example:
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.

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

추가 답변 (1개)

Sai Bhargav Avula
Sai Bhargav Avula 2020년 5월 18일
편집: Sai Bhargav Avula 2020년 5월 18일
Hi,
Try the following code
convert matrix to char
matrix ='001001001111011101111';
matrix=reshape(matrix,[],3);
Hope this helps!
  댓글 수: 7
Shehab Tarek
Shehab Tarek 2020년 5월 18일
편집: Shehab Tarek 2020년 5월 18일
thanks in advance sir
Sai Bhargav Avula
Sai Bhargav Avula 2020년 5월 18일
편집: Sai Bhargav Avula 2020년 5월 18일
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 .
The answer should have been like what David answered
matrix ='001001001111011101111';
matrix= string(reshape(matrix,3,[])');

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

카테고리

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