How can I increment different values for every iteration to a for loop?

22 次查看(过去 30 天)
Hi! I'm at stall of my program because of this. I would like to increment different values for every iteration in a for loop but sad to say I can't find a solution. BTW, I'm still a newbie. Here is an example:
a = [1 3 4 7 8 10 14 17 21 26];
for k=a(1):X:a(end) %X is the increment
disp(k) %displays k
end
I need to obtain 10 iterations that displays k which is the values of a. Hope you can help me.

采纳的回答

Robert Cumming
Robert Cumming 2014-7-26
for k=1:length (a)
disp ( a(k) );
end

更多回答(1 个)

fengwuxiaoli
fengwuxiaoli 2017-12-4
a = [1 3 4 7 8 10 14 17 21 26]; for k=a disp(k); end

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by