can text next to input be different in each loop?

2 次查看(过去 30 天)
for i =1 : 5
fprintf('Enter Height %d', i)
x=input('');
end
is there a neater way to write this code ?
i.e : use one function only

采纳的回答

Luna
Luna 2019-2-19
编辑:Luna 2019-2-19
Hi,
Input can get prompt string as an input already. You can use both:
promptString = 'Enter Height';
for i = 1:5
x=input([promptString,' ', num2str(i),': ']);
end
%% OR %%
promptString = 'Enter Height';
for i = 1:5
x=input([promptString,' ', sprintf('%d',i),': ']);
end

更多回答(0 个)

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by