Info
Questa domanda è chiusa. Riaprila per modificarla o per rispondere.
how can i pull different location with same maximum result
    3 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
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 Commenti
  VBBV
      
      
 il 1 Ott 2020
				
      Modificato: VBBV
      
      
 il 1 Ott 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
Risposte (0)
Questa domanda è chiusa.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!