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

10 次查看(过去 30 天)
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

采纳的回答

Image Analyst
Image Analyst 2018-3-3
Try this
x=1:6;
y = reshape(x, 2, [])'
You'll see
y =
1 2
3 4
5 6

更多回答(1 个)

elham kreem
elham kreem 2018-3-4
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]

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by