How can i make this code dynamic?
Mostrar comentarios más antiguos
function gr = semm(p,k)
if nargin < 2
b=[30,15,6];
end
gr=s;
gr(:)=4;
gr(p> 100 ) = "Not valid output";
gr(p >= k(3) ) = 3;
gr(p >= k(2) ) = 2;
gr(p >= k(1) ) = 1;
How can I make the above code dynamic so that It doesn't have k(1),k(2),k(3) and it can see at run time the vector k and decide which gr to assign to each element in p?
P.s- any help is appreciated.
3 comentarios
Walter Roberson
el 29 de Oct. de 2020
Editada: Walter Roberson
el 29 de Oct. de 2020
? Should your b all have been k ? Should yolur s have been p ?
Walter Roberson
el 29 de Oct. de 2020
Is there a guarantee that k is sorted in descending order? If it is not sorted, then should the output be as-if it were sorted, or should the output be according to the logic you posted, where the first value in k for which the conditions hold determines the output? For example if k were [15,30,6] then should input 33 be output 2 (position 2 of k holding the greatest value that does not exceed the input), or should it be output 1 (because even though 33 > 30 is true and the most restrictive, your logic would test >= 15 after that and replace the 2 with a 1) ?
shubham shubham
el 29 de Oct. de 2020
Editada: shubham shubham
el 29 de Oct. de 2020
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Shifting and Sorting Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!