I want to create a program that will ask the user 3 times for there firstname, lastname and number, and then store all the results within a matrix or array. So far I can only get it for the last result. Thankyou
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
n=0
while n ~= 3
a = string(input('Firstname: ' , 's'));
b = string(input('Lastname: ' , 's'));
c = string(input('Number: ' , 's'));
n = n+1
A = [a b c]
end
0 commentaires
Réponse acceptée
Nick
le 14 Avr 2017
Someone might have a better or more efficient way of doing this, but I would use a cell array and a for loop and assign it that way.
A = {}
for i = 1 : 3
A{i,1} = string(input('Firstname: ' , 's'));
A{i,2} = string(input('Lastname: ' , 's'));
A{i,3} = string(input('Number: ' , 's'));
end
Then you can read the different value A{1,2} etc
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Cell Arrays 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!