Program to perform a reshape of an array

2 次查看(过去 30 天)
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,[]);

类别

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