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
답변 (2개)
James Tursa
2015년 2월 18일
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);
the cyclist
2015년 2월 18일
0 개 추천
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.
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!