How can i make this code dynamic?
Afficher commentaires plus anciens
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 commentaires
Walter Roberson
le 29 Oct 2020
Modifié(e) : Walter Roberson
le 29 Oct 2020
? Should your b all have been k ? Should yolur s have been p ?
Walter Roberson
le 29 Oct 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
le 29 Oct 2020
Modifié(e) : shubham shubham
le 29 Oct 2020
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Shifting and Sorting Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!