MATLAB: Can you have a script display cases in switch statement that were not used

selectionswitch statement

For this code assume case 1, 2, and 4 were called but i want it that any order could be called. Can you display case 3 and 5 as not being called or case 1 and 4. what ever input the user doesn't provide could it be displayed. Example below.
fileName = input('Please enter the file name: ', 's');
%Company r
Company = 'r';
contact_1 = 'adam';
r_team = {};
r_count = 0;
while 1
crew_num = input('Enter number: ');
if crew_num == 0
break;
end
switch crew_num
case 1
r_crew = 'adam';
case 2
r_crew = 'steve';
case 3
r_crew = 'john';
case 4
r_crew = 'jeff';
case 5
r_crew = 'scott';
otherwise
continue;
end
r_count = r_count +1;
r_team{r_count} = r_crew;
fprintf('Current Crew Count: %d\n', r_count);
fprintf('\n');
end
fprintf('\n');
fprintf('%s\n', fileName);
fprintf('\n')
fprintf('Company: %s\n', Company);
fprintf('Foreman: %s\n', contact_1);
fprintf('R crew member count: %d\n', r_count);
disp('Crew Member Names:');
fprintf('%s, ', r_team{:});
fprintf('\n\n');
Examples of result would be:
Crew member no show:
steve, scott,
This would be displayed in command window below the other results.
The input from the user would not have included 2 and 5.
I don't know if this is possible and why I am looking if there is a way to do this.
Thank you,

Best Answer

  • switch crew_num
    case 1
    r_crew = 'adam';
    showedup(1) = true;
    case 2
    r_crew = 'steve';
    showedup(2) = true;
    case 3
    r_crew = 'john';
    showedup(3) = true;
    case 4
    r_crew = 'jeff';
    showedup(4) = true;
    case 5
    r_crew = 'scott';
    showedup(5) = true;
    otherwise
    continue;
    end
    And afterwards look for entries not set.
    Have you considered the possibility of indexing into a cell array of character vectors? Validate that the entered number is a positive integer and in range, and then index?
    Have you considered the possibility of using menu() to choose crew members?