Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

how can i pull different location with same maximum result

1 visualización (últimos 30 días)
Samantha Pham
Samantha Pham el 1 de Oct. de 2020
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
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 comentarios
VBBV
VBBV el 1 de Oct. de 2020
Editada: VBBV el 1 de Oct. de 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

Respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by