suppose x=[1 2 3 4 5 6] and y(1)=[1 2],y(2)=[3 4],y(3)=[5 6].how can i take like this in matlab
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MAMATHA YADAVALLI
le 3 Mar 2018
Réponse apportée : elham kreem
le 4 Mar 2018
x=1:6;
j=1:2:6
for i=1:3
for k=1:length(j)
y(i)=[x(k) x(k+1)];
end
end
1 commentaire
David Fletcher
le 3 Mar 2018
you could just reshape the matrix and then index it by column:
reshape(1:6,2,3)
ans =
1 3 5
2 4 6
or transpose that if you wanted it by rows
Réponse acceptée
Image Analyst
le 3 Mar 2018
Try this
x=1:6;
y = reshape(x, 2, [])'
You'll see
y =
1 2
3 4
5 6
0 commentaires
Plus de réponses (1)
elham kreem
le 4 Mar 2018
or this :
x=1:6;
k=1
y1=[x(k) x(k+1)];
y2=[x(k+2) x(k+3)];
y3=[x(k+4) x(k+5)];
y= [ y1 y2 y3]
or
y= [ y1 ; y2 ; y3]
0 commentaires
Voir également
Catégories
En savoir plus sur Matrix Indexing 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!