Using reshape function i get wrong ans....

b=[0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1];
>> SS=reshape(b,length(b)/8,8);
>> SS
SS =
0 0 0 0 0 0 0 0
1 0 1 0 1 0 1 0
0 0 0 0 0 0 0 0
0 1 0 1 0 1 0 1
bt i want to get
SS =
0 1 0 0 0 0 1 0
0 1 0 0 0 0 1 0
0 1 0 0 0 0 1 0
0 1 0 0 0 0 1 0
ie what my array b data.. thats i want to be in SS.. how i write code? Help me

1 commentaire

Jan
Jan le 18 Mai 2015
Where does the trailing zero column come from? It is not clear why the last and teh 2nd last column seem to have swapped.

Connectez-vous pour commenter.

 Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 18 Mai 2015
b=[0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1];
SS=reshape(b,8,[]);
SS([end,end-1],:) = SS([end-1,end],:);
SS = SS';

6 commentaires

Guillaume
Guillaume le 18 Mai 2015
Modifié(e) : Guillaume le 18 Mai 2015
I strongly suspect that the Arjun has got his example slightly wrong and that this step:
SS([end,end-1],:) = SS([end-1,end],:);
is unwanted. I.e, the correct answer is most likely:
SS = reshape(b, 8, [])'
@Arjun, reshape rearranges the elements by column (since matlab is column major). So, the answer is to rearrange the elements in columns of 8 rows and then transpose.
ARJUN K P
ARJUN K P le 18 Mai 2015
ans Wrong....
i didnt get the ans... help me
Jan
Jan le 18 Mai 2015
As your screen shot shows, you get exactly the answer you've asked for. If this is not the answer you want, please give us a chance to help you and post exactly, what you want.
ARJUN K P
ARJUN K P le 18 Mai 2015
Modifié(e) : ARJUN K P le 18 Mai 2015
sry its my mistake..
b=[0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1]; i want to group each 8 bits in array b.. that is i want my ans like
0 1 0 0 0 0 0 1
0 1 0 0 0 0 0 1
0 1 0 0 0 0 0 1
0 1 0 0 0 0 0 1
ARJUN K P
ARJUN K P le 18 Mai 2015
thanku all i got ans.... special thanks to Andrei Bobrov code is working

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by