Info

This question is closed. Reopen it to edit or answer.

how can i pull different location with same maximum result

3 views (last 30 days)
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 Comments
VBBV
VBBV on 1 Oct 2020
Edited: VBBV on 1 Oct 2020
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

Answers (0)

This question is closed.

Tags

Community Treasure Hunt

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

Start Hunting!