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

2 ビュー (過去 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
  1 件のコメント
Muhammad Ammar Fiqri Bin Johari Johari
Thank You for your information. Its what i required for my current coding arrangement. Appreciate your help

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by