Performing actions on a multiple choice list
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Walter Roberson
le 7 Fév 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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!