Asking user for input, returning a matrix
8 views (last 30 days)
Show older comments
For a group project, we are supposed to ask the user how many rows and columns they would like and then return a matrix of that size. I'm really struggling with this. Right now this is what I have, and its not working.
prompt1 = 'How many rows?'
A = input('prompt1')
prompt2 = 'How many columns?'
B = input('prompt2')
ourCase = [A; B]
Not sure where I'm going wrong at, but any input/help would be greatly appreciated
0 Comments
Answers (2)
James Tursa
on 18 Feb 2015
You are close. Just a few syntax things to clear up.
input('prompt1') uses the explicit string 'prompt1' as the prompt text. You want to use the text that is in your variable prompt1. So do this instead:
A = input(prompt1);
same for B:
B = input(prompt2);
Then to make a matrix of size A x B, there are various ways of doing that. One of the standard methods is using the zeros function:
ourCase = zeros(A,B);
0 Comments
the cyclist
on 18 Feb 2015
If the user submits 3, and then 4, then ourCase is going to be the vector
[3; 4]
In that last line, you need to create a 3x4 matrix instead. There are a number of ways to do that.
0 Comments
See Also
Categories
Find more on Data Type Conversion 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!