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!