Effacer les filtres
Effacer les filtres

Program to perform a reshape of an array

2 vues (au cours des 30 derniers jours)
Ronald Niwamanya
Ronald Niwamanya le 26 Mai 2021
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.

Réponse acceptée

Jan
Jan le 26 Mai 2021
Modifié(e) : Jan le 26 Mai 2021
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 commentaire
Ronald Niwamanya
Ronald Niwamanya le 27 Mai 2021
Thank you @Jan for the guidance.

Connectez-vous pour commenter.

Plus de réponses (1)

darova
darova le 26 Mai 2021
Use reshape without for loop
M = reshape(W',4,[]);
  1 commentaire
Ronald Niwamanya
Ronald Niwamanya le 26 Mai 2021
Thank you but still it does not give the output.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Matrices and Arrays 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