Performing actions on a multiple choice list
1 次查看(过去 30 天)
显示 更早的评论
function year = year_choose
year = listdlg('SelectionMode','multiple','PromptString',...
'Choose two Years','ListString',{'2017', '2018', '2019'});
promptMessage = sprintf(['Would you like to continue with ...' ...
'your chosen year? ,\nor Cancel to abort processing?']);
button = questdlg(promptMessage, 'Continue', 'Continue', 'Cancel', 'Continue');
if strcmp(button, 'Cancel')
return; % or break or whatever...
end
if year == 1 && 2
fprintf('You have chosen:\n2017');
elseif year == 2
fprintf('You have chosen:\n2018');
elseif year == 3
fprintf('You have chosen:\n2019');
end
end
Here is my code, so this code brings up a list for the user to select from, their are three value and the user is only going to
choose 2 of them however say for example they choose '2017 and 2018', it stores their answer as the value [1,2]. How do i then
reference their choice and use fprintf to display their choice to later use in a plot. I tried to do it in the 'if' statement
using the operand && but it gave me an error.
0 个评论
采纳的回答
Walter Roberson
2021-2-7
if length(year) ~= 2
error('You choose the wrong number of years, should have chosen 2');
end
if ismember(1, year)
fprintf('You have chosen:\n2017\n');
end
if ismember(2, year)
fprintf('You have chosen:\n2018\n');
end
if ismember(3, year)
fprintf('You have chosen:\n2019\n');
end
selected_years = sort(year + 2017 - 1); %sort is probably not needed
7 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!