Program to perform a reshape of an array

조회 수: 2 (최근 30일)
Ronald Niwamanya
Ronald Niwamanya 2021년 5월 26일
댓글: Ronald Niwamanya 2021년 5월 27일
Greetings of the day
I have W and would like to obtain P as indicated below.
W=[1 1 1 1 0 1 1 1;0 1 1 1 1 1 0 1;1 0 1 0 1 1 0 1;1 1 0 0 1 1 0 1;1 1 0 0 1 1 0 0]
for k=1:5
M=reshape(W(k,:),4,2)
end
P=bi2de(M)
%Modify the above program and obtain a matrix that contains all values as
%follows:
P=[2 3 3 3;1 3 2 3;3 1 2 1;3 3 0 1;3 3 0 0];
Thank you so much.

채택된 답변

Jan
Jan 2021년 5월 26일
편집: Jan 2021년 5월 26일
W = [1 1 1 1 0 1 1 1; ...
0 1 1 1 1 1 0 1; ...
1 0 1 0 1 1 0 1; ...
1 1 0 0 1 1 0 1; ...
1 1 0 0 1 1 0 0];
M = fliplr(reshape(W, 20, 2));
P = reshape(bi2de(M), 5, 4)
P = 5×4
2 3 3 3 1 3 2 3 3 1 2 1 3 3 0 1 3 3 0 0

추가 답변 (1개)

darova
darova 2021년 5월 26일
Use reshape without for loop
M = reshape(W',4,[]);
  댓글 수: 1
Ronald Niwamanya
Ronald Niwamanya 2021년 5월 26일
Thank you but still it does not give the output.

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

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by