Asking user for input, returning a matrix

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

Answers (2)

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);
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.

Categories

Asked:

on 18 Feb 2015

Answered:

on 18 Feb 2015

Community Treasure Hunt

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

Start Hunting!