How to make input values go into a matrix set?
Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Ältere Kommentare anzeigen
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 Kommentare
Daniil Hart
am 21 Okt. 2020
Fangjun Jiang
am 21 Okt. 2020
then you have to enter " [ 2 , 4 ] "
Antworten (1)
Fangjun Jiang
am 21 Okt. 2020
InputStr= input(' Enter coordinate point location (x,y)','s');
Command Window: >> 2 , 4
PointA=str2num(InputStr)
2 Kommentare
Daniil Hart
am 21 Okt. 2020
Fangjun Jiang
am 22 Okt. 2020
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
Diese Frage ist geschlossen.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!