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

1 回表示 (過去 30 日間)
shay kent
shay kent 2022 年 4 月 21 日
回答済み: Riya 2024 年 2 月 1 日
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?

回答 (1 件)

Riya
Riya 2024 年 2 月 1 日
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.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by