For Loop in Data

1 次查看(过去 30 天)
rrv
rrv 2019-5-8
编辑: Jan 2019-5-9
How can I convert those y's in just one FOR loop?
x= [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0 ];
y1=x(2:end) - x(1:end-1)
y2=x(3:end) - x(1:end-2)
y3=x(4:end) - x(1:end-3)
y4=x(5:end) - x(1:end-4)

采纳的回答

Jan
Jan 2019-5-8
编辑:Jan 2019-5-9
x = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0 ];
y = cell(1, 4);
for k = 1:4
y{k} = x(1-k:end) - x(1:end-k);
end
Prefer a cell array instead of hiding indices in the names of variables.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by