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 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Nick
Nick el 14 de Abr. de 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

Más respuestas (0)

Categorías

Más información sobre Cell Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by