Inputdlg requesting input to provide an output of 6 integers as a row vector
2 次查看(过去 30 天)
显示 更早的评论
采纳的回答
Stephen23
2018-2-19
编辑:Stephen23
2018-2-19
Do NOT use str2num! Using sscanf is faster than str2num (and avoids the internal eval call that str2num hides inside):
>> c = inputdlg('Enter six space-separated integers:')
>> v = sscanf(c{1},'%d',[1,Inf])
v =
1 2 3 4 5 6
To ensure that there are six integers either add an assert:
assert(numel(v)==6,'Input exactly six integers.')
or a while loop:
v = [];
while numel(v)~=6
c = inputdlg('Enter six space-separated integers:');
v = sscanf(c{1},'%d',[1,Inf])
end
0 个评论
更多回答(1 个)
ES
2018-2-19
inputdata = [];
while(~isequal(size(inputdata), [1,6]))
x = inputdlg('Enter 6 integers as space-separated numbers:',...
'Sample', [1 50]);
inputdata = str2num(x{:});
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!