Store 2 inputs in 2 arrays

조회 수: 1 (최근 30일)
LR
LR 2021년 5월 7일
편집: LR 2021년 5월 7일
The 'coordX' input is stored in an array but how do I get the 'coordY' input to be stored in a second array?
Thanks in advance for any help.
data=[];
totalX=0;
totalY=0;
numberOfCoordinates=input('Please input the number of coordinates:');
data=zeros(1,numberOfCoordinates);
for i=1:1:numberOfCoordinates
coordX(i)=input('Please enter the X co-ordinate:' )
for i=1:1:coordX
coordY (i)=input ('Please enter the Y co-ordinate:')

답변 (1개)

Mouhamed Niasse
Mouhamed Niasse 2021년 5월 7일
data=[];
totalX=0;
totalY=0;
numberOfCoordinates=input('Please input the number of coordinates:');
data=zeros(1,numberOfCoordinates);
for i=1:numberOfCoordinates
coordX(i)=input('Please enter the X co-ordinate of a corner of the field:' )
end
for i=1:max(size(coordX))
coordY (i)=input ('Please enter the Y co-ordinate of a corner of the field:')
end
  댓글 수: 1
LR
LR 2021년 5월 7일
편집: LR 2021년 5월 7일
I've tried using your code but I'm finding when I use it with the other code I need to include, it repeats requests for coordinates. For example if I say there are 3 coordinates it should ask for 6 inputs but instead it asks for 9. See the updated code is below, thanks.
data=[];
totalX=0;
totalY=0;
numberOfCoordinates=input('Please input the number of coordinates:');
data=zeros(1,numberOfCoordinates);
if numberOfCoordinates<3
disp(['Less than 3 coordinates have been entered']);
else
for i=1:numberOfCoordinates
coordX(i)=input('Please enter the X co-ordinate of a corner of the field:' )
for i=1:max(size(coordX))
coordY (i)=input ('Please enter the Y co-ordinate of a corner of the field:')
end
end
end

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 3-D Scene Control에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by