Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
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

Réponse acceptée

Nick
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)

Catégories

En savoir plus sur Logical 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!

Translated by