Performing actions on a multiple choice list
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
Walter Roberson
on 7 Feb 2021
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 Comments
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!