input a 1*3 vector
조회 수: 1 (최근 30일)
이전 댓글 표시
how can I make the user inputs an array of 1*3 dimensions for example x=input('your guess') x= [# # #]
댓글 수: 0
답변 (3개)
Walter Roberson
2015년 11월 11일
while true
xs = input('enter your guess (a list of three numbers)', 's');
xs = regexprep(xs, '^\[(.*)\]', '$1');
s = regexp(xs, '(\s|,)+', 'split');
if length(s) ~= 3
warning('Wrong number of entries, need 3');
continue;
end
x = str2double(s);
if any(isnan(x))
warning('Something was not a number!');
continue;
end
break;
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!