can text next to input be different in each loop?

조회 수: 1 (최근 30일)
Abdelrhman Mahmoud
Abdelrhman Mahmoud 2019년 2월 19일
편집: Luna 2019년 2월 19일
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