Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How to make input values go into a matrix set?

조회 수: 1 (최근 30일)
Daniil Hart
Daniil Hart 2020년 10월 21일
마감: MATLAB Answer Bot 2021년 8월 20일
How can make the script ask for you to type in two values and have it store those two values into a matrix?
example:
Point A = input(' Enter coordinate point location (x,y)
Command Window: >> 2 , 4
Then is stores those two as PointA = [ 2 , 4 ]
is there any way to do that without you having to enter " [ 2 , 4 ] " into the command window??
the only way i've figured out so far is doing this but it requires a seperate input for each value like ive shown below, is there a way to simplify?
d = input(" Enter X value for A \n");
e = input(" Enter Y value for A \n");
f = input(" Enter X value for B \n");
g = input(" Enter Y value for B \n");
h = input(" Enter X value for C \n");
i = input(" Enter Y value for C \n");
PointA = [ d , e ];
PointB = [ f , g ];
PointC = [ h , i ];
  댓글 수: 2
Daniil Hart
Daniil Hart 2020년 10월 21일
To clarify is there a way to turn
d = input(" Enter X value for A \n");
e = input(" Enter Y value for A \n");
into one step, so you could enter both d and e in a single step?
Fangjun Jiang
Fangjun Jiang 2020년 10월 21일
then you have to enter " [ 2 , 4 ] "

답변 (1개)

Fangjun Jiang
Fangjun Jiang 2020년 10월 21일
InputStr= input(' Enter coordinate point location (x,y)','s');
Command Window: >> 2 , 4
PointA=str2num(InputStr)
  댓글 수: 2
Daniil Hart
Daniil Hart 2020년 10월 21일
Thank you! That works, however I'm not sure if my prof will even accept that since we haven't covered that command yet.
Fangjun Jiang
Fangjun Jiang 2020년 10월 22일
Or a stretch code like this, no duplicated code, no fancy functions, no unnecessary typing for the user
%%
PointA=[0 0];
Msg={'x','y'};
for k=1:2
PointA(k)=input(['Enter ',Msg{k},' value for A\n']);
end

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by