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!