Is it possible to make a loop where the the result is separate from the loop and have the result respectively with the input?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ahmad Rushaidi
le 19 Jan 2021
Commenté : Ahmad Rushaidi
le 19 Jan 2021
%%
clc,clear
product=input('Quantity of product you have bought today: ');
for a=1:product
food=input('Why is food so tasty?: ','s');
end
for a=1:product
fprintf('\nBecause it is %s \n',food)
end
****************************************************************************************************************
Quantity of product you have bought today: 2
Why is food so tasty?: idk
Why is food so tasty?: dk
Because it is dk <-----this one suppose to be idk
Because it is dk
>>
Réponse acceptée
Stephen23
le 19 Jan 2021
Use a cell array to store the data:
p = 'Quantity of product you have bought today: ';
n = str2double(input(p,'s'));
c = cell(1,n);
for k = 1:n
c{k} = input('Why is food so tasty?: ','s');
end
fprintf('\nBecause it is %s \n',c{:})
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!