Effacer les filtres
Effacer les filtres

reshape a matrix or cell array

1 vue (au cours des 30 derniers jours)
Ahmed Hassaan
Ahmed Hassaan le 29 Mar 2012
Hello , I am sorry for repetition i asked this question and deleted it by wrong and want to discuss it again , first my question is when i ave a matrix like this :
a=[1
2
3
4]
and i want to convert it to this form
a=[1 2
3 4
5 6]
if i do a reshape
B=reshape(a,[],2)
B =
1 3
2 4
this is a simple example my code have this function to implement it
ENDBR = arrayfun( @(IDX) nonzeros(MY_ARRAY(IDX,:)), 1:size(MY_ARRAY,1), 'Uniform', 0);
thanks

Réponse acceptée

Thomas
Thomas le 29 Mar 2012
do
b=reshape(a,[],2)'
to get
b =
1 2
3 4
correction will work for more than 2 rows:
a=[1:10]';
b=reshape(a,2,[])'
b =
1 2
3 4
5 6
7 8
9 10
  2 commentaires
Ahmed Hassaan
Ahmed Hassaan le 29 Mar 2012
well, this works if the number of rows is 2 if it exceeds two it will do nothing
Thomas
Thomas le 29 Mar 2012
try
a=[1:10]';
b=reshape(a,2,[])'
b =
1 2
3 4
5 6
7 8
9 10

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by