Info
此问题已关闭。 请重新打开它进行编辑或回答。
how can i pull different location with same maximum result
1 次查看(过去 30 天)
显示 更早的评论
Hi, this is my code and the table i used for this function.
When i put this code
[AlloyMAX,maxNUM,ELEMENTless] = Task4(1.2,Element,Alloy,Percent)
the ELEMENTless give me the right result
but when i used
[AlloyMAX,maxNUM,ELEMENTless] = Task4(1.7,Element,Alloy,Percent)
The ELEMENTless is not giving me location as it should based on the maximum number.
Thank you very much!

function [AlloyMAX,maxNUM,ELEMENTless] = Task4(USERpercent,Element,Alloy,Percent)
Condition = Percent > 0 & Percent < USERpercent;
SUMvector = sum(Condition,2);
[maxNUM, Loc] = max(SUMvector);
AlloyMAX = Alloy(Loc);
ELEMENTless = Element(Condition(maxNUM,:));
end
all the codes was right for the test case 1, not test case 2
2 个评论
VBBV
2020-10-1
编辑:VBBV
2020-10-1
May be The condition defined inside the function Task4 is not satisfied.
% if true
% code
% end
function [AlloyMAX,maxNUM,ELEMENTless] = Task4(USERpercent,Element,Alloy,Percent)
Condition = Percent > 0 | Percent < USERpercent; % try using OR operator
SUMvector = sum(Condition,2);
[maxNUM, Loc] = max(SUMvector,[],'linear');% use linear option for loc
AlloyMAX = Alloy(Loc);
ELEMENTless = Element(Condition(maxNUM,:));
end
回答(0 个)
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!