I want to create a a user generated matrix with multiple subcategories

1 Ansicht (letzte 30 Tage)
shay kent
shay kent am 21 Apr. 2022
Beantwortet: Riya am 1 Feb. 2024
I wat to create a user inferface that asks questions based on previous answers and then outputs the summary of the questions answered. For instance, "please enter the file number" and then "enter the number of conditions" and the user inputs a number, say "6", then the program would start with the number 1 and ask "is this direct, 3-step or red". The program would then keep going through the set of questions and when all the questions had been answered for number 1, it would move to number 2 and so on until it had gone through every condition. I would then want all of this information to output to the screen in a list format with the same number of rows as the "conditions" number and a set number of questions would be the number of columns. Im assuming this is just nested "if" statements?

Antworten (1)

Riya
Riya am 1 Feb. 2024
Hi
The process you're describing isn't just nested "if" statements; it's more of a loop that iterates over a set of conditions, asking a series of questions for each condition. You would use conditionals within this loop to handle the different types of responses.
Here is a high-level pseudocode outline of how you might structure this program:
% MATLAB script for generating a user-defined matrix based on a series of questions
% Ask for the file number
fileNumber = input('Please enter the file number: ', 's');
% Ask for the number of conditions
numberOfConditions = input('Enter the number of conditions: ');
% Initialize a cell array to store the conditions
conditionsList = cell(numberOfConditions, 2); % Assuming only file number and type are stored
% Loop over the number of conditions
for i = 1:numberOfConditions
% Ask the first question
fprintf('For condition %d:\n', i);
type = input('Is this direct, 3-step, or red? ', 's');
% Store the condition information in the cell array
conditionsList{i, 1} = fileNumber;
conditionsList{i, 2} = type;
% Add additional questions and store the answers if necessary
% ...
end
% Output the summary
fprintf('\nSummary of conditions:\n');
for i = 1:numberOfConditions
% Output each condition's information in a list format
fprintf('Condition %d: File Number - %s, Type - %s\n', i, conditionsList{i, 1}, conditionsList{i, 2});
% Add additional information output here if necessary
% ...
end% MATLAB script for generating a user-defined matrix based on a series of questions
% Ask for the file number
fileNumber = input('Please enter the file number: ', 's');
% Ask for the number of conditions
numberOfConditions = input('Enter the number of conditions: ');
% Initialize a cell array to store the conditions
conditionsList = cell(numberOfConditions, 2); % Assuming only file number and type are stored
% Loop over the number of conditions
for i = 1:numberOfConditions
% Ask the first question
fprintf('For condition %d:\n', i);
type = input('Is this direct, 3-step, or red? ', 's');
% Store the condition information in the cell array
conditionsList{i, 1} = fileNumber;
conditionsList{i, 2} = type;
% Add additional questions and store the answers if necessary
% ...
end
% Output the summary
fprintf('\nSummary of conditions:\n');
for i = 1:numberOfConditions
% Output each condition's information in a list format
fprintf('Condition %d: File Number - %s, Type - %s\n', i, conditionsList{i, 1}, conditionsList{i, 2});
% Add additional information output here if necessary
% ...
End
In a real implementation, you would need to handle user input validation, potential errors, and possibly a more complex user interface.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by