How do I check/verify that an array is a certain dimension?

조회 수: 17 (최근 30일)
t sizzle
t sizzle 2021년 4월 20일
댓글: Matt J 2021년 4월 20일
I have an array that is 1x2, but I am trying to ensure that the array MUST be 1x2 and not any smaller or larger. The array is made up of user inputs, [x,y], and I want to make sure they do not accidentally input just an X coordinate or Y coordinate. So far this is what I have. How can I ensure that they will be prompted to enter the values again until there are two values, one for x, and one for y.
What I have tried below is not working.
point = input('Please input a point [x,y]: ');
size(point);
while size(point) ~= [1:2]
point = input('Please input a point [x,y]: ');
end

채택된 답변

Matt J
Matt J 2021년 4월 20일
편집: Matt J 2021년 4월 20일
while ~isequal(size(point),[1,2])
  댓글 수: 2
t sizzle
t sizzle 2021년 4월 20일
This worked. Thank you so much.
Matt J
Matt J 2021년 4월 20일
You're welcome, but please Accept-click the answer to indicate that that's the case.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by