Hi Everyone. Ive created a set of questions for user to select the material characteristics based on their preferences and need help to choose best results best on their ans

조회 수: 1 (최근 30일)
Below is the coding. i want to show user which material between is the best based on average answer. Kindly need your help.
x=input('enter required strength /10 =');
if x>0 && x<=5
save ('AS')
save ('AA')
elseif x>5 && x<=8
save ('PL')
elseif x>8 && x<=10
save ('PC')
end
t=input('choose hardness 75/80/90/100 =');
if t==75
save('PL')
elseif t==80
save('PC')
elseif t==90
save('AA')
elseif t==100
save('AS')
end
reply=input('enter expected finishing low-med-high : ','s');
if strcmp(reply,'low')
save('AS')
elseif strcmp(reply,'med')
save('PC and PL')
elseif strcmp(reply,'high')
save('AA')
end
  댓글 수: 4
Rik
Rik 2022년 12월 30일
And how would you solve this with pen and paper? Would you have some sort of points system so at the end you can select the option with the most points?
You need to do something in each branch that you can keep track of. Presumably that is what you intended with the save calls. The save calls resulted in the creation of mat files. What could you replace that with? Based on a set of answers, how do you want to determine the best?
Muhammad Ammar Fiqri Bin Johari Johari
Understand that. I can say it can come as a point system. For example out of 3 questions answered by user, if 2 out of 3 of the answer selected is PL and 1 is AS , thus the final result will show that best material is PL and user will see the answers from the final result. If i may ask, what type of code that i can identify for each branch that can support such arrangement? Appreciate your help.

댓글을 달려면 로그인하십시오.

채택된 답변

Karim
Karim 2022년 12월 30일
Hi, see below for some possibilities on how to code such selection.
% material options
Materials = ["AS";"AA";"PL";"PC"];
Strength = zeros(numel(Materials),1);
Hardness = zeros(numel(Materials),1);
Finishing = zeros(numel(Materials),1);
SelectionTable = table(Materials,Strength,Hardness,Finishing);
% get user input
% Strength = input('enter required strength /10 =');
% Hardness = input('choose hardness 75/80/90/100 =');
% Finishing = input('enter expected finishing low-med-high : ','s');
% user inputs is not possible online, hence pick some random results:
Strength = 4;
Hardness = 80;
Finishing = 'med';
% logic for the strength
if Strength>0 && Strength<=5
SelectionTable.Strength([1,2]) = 1;
elseif Strength>5 && x<=Strength
SelectionTable.Strength(3) = 1;
elseif Strength>8 && Strength<=10
SelectionTable.Strength(4) = 1;
end
switch Hardness
case 75; SelectionTable.Hardness(3) = 1;
case 80; SelectionTable.Hardness(4) = 1;
case 90; SelectionTable.Hardness(2) = 1;
case 100; SelectionTable.Hardness(1) = 1;
end
switch lower(Finishing)
case 'low'; SelectionTable.Finishing(1) = 1;
case 'med'; SelectionTable.Finishing([3,4]) = 1;
case 'high'; SelectionTable.Finishing(2) = 1;
end
% print the final selection table, this gives an overview of the material
% possibilities based on the user choises and the selection logic
SelectionTable
SelectionTable = 4×4 table
Materials Strength Hardness Finishing _________ ________ ________ _________ "AS" 1 0 0 "AA" 1 0 0 "PL" 0 0 1 "PC" 0 1 1
% to make a suggestion, we could pick the material that has the most 1's:
Suggestion = sum(SelectionTable{:,2:end},2)
Suggestion = 4×1
1 1 1 2
[~,materialIdx] = max(Suggestion)
materialIdx = 4
fprintf('Based on the user inputs, the recommended material is %s \n',SelectionTable{materialIdx,1})
Based on the user inputs, the recommended material is PC

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by