Clear Filters
Clear Filters

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 views (last 30 days)
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

Accepted Answer

Nick
Nick on 14 Apr 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

More Answers (0)

Categories

Find more on Cell Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!