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

1 次查看(过去 30 天)
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

采纳的回答

Nick
Nick 2017-4-14
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by