Conditional function on matrix
조회 수: 8 (최근 30일)
이전 댓글 표시
Hello,
This is a tough one to explain.
I am analysing a big chunk of data and now I have a equation defined by intervals.
Kd=1 for Kt<0.2
Kd=e for 0.2<=Kt<=1.09*c2
Kd=f for Kt>1.09*c2
Kt=rand(8784,89);
c2=ones(size(Kt))/2;
e=rand(size(Kt));
f=rand(size(Kt));
I've simplified it quite a bit, because it envolves other matrixes (all with the same size (8784,89)) on the conditions.
My question is, how to execute it? I've tried piecewise, but I'm stuck with the symbolic. I would need to get Kd as double.
Kd(Kt)=piecewise(Kt<0.2,1, 0.2<=Kt<=1.09*c2,10, Kt>1.09*c2,5);
I've tried with If and elseif but as far as I've seen it will only analyze the first element of the array to verify if the condition is true:
if Kt<0.2
Kd=1;
elseif 0.2<=Kt<=1.09*c2
Kd=e;
elseif Kt>1.09*c2
Kd=f;
end
Other ideas or something I'm missing?
edit: edited after trying solution given by Matt J.
thanks.
댓글 수: 0
채택된 답변
Matt J
2019년 4월 23일
편집: Matt J
2019년 4월 23일
vals=[1,10,5];
Kd=vals( discretize(Kt,[-inf,0.2,1.09*c2,+inf]) );
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Interpolation of 2-D Selections in 3-D Grids에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!