How can i make this code dynamic?
이전 댓글 표시
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
Walter Roberson
2020년 10월 29일
편집: Walter Roberson
2020년 10월 29일
? Should your b all have been k ? Should yolur s have been p ?
Walter Roberson
2020년 10월 29일
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
2020년 10월 29일
편집: shubham shubham
2020년 10월 29일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!