fprintf and for loop

7 次查看(过去 30 天)
Anna Cole
Anna Cole 2018-10-17
编辑: Dennis 2018-10-17
I want the following output:
period 1 step 1
save
period 1 step 2
save
period 2 step 1
save
and continue on in this manner.
I wrote the following code but I'm just getting it to print period (i) ten times over in one line.
for i=1:10
for j=1:2
fprintf("period (i)", "step (j)", '\n', '\t', "save")
end
end

采纳的回答

Dennis
Dennis 2018-10-17
编辑:Dennis 2018-10-17
for i=1:10
for j=1:2
fprintf('period %d step %d \nsave\n',i,j)
end
end

更多回答(0 个)

类别

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

标签

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by