The following code is correct?

I have a Ph of size 139 48 101 values ranging say 0 to 0.4, now to compute Kd from Ph have two equations if Ph is equal or less than 0.35 and if Ph is greater than 0.35. I used following code to apply two equation. Have I done it correctly?
Kd = zeros(size(Ph));
% Find indices where Ph is less than or equal to 0.35
indices1 = Ph <= 0.35;
% Find indices where Ph is greater than 0.35
indices2 = Ph > 0.35;
% Apply the first equation to 'kd' where PhiE is less than or equal to 0.35
Kd(indices1) = 38.18.*(1-3.39.*Ph(indices1)+1.95.*Ph(indices1).^2).*1e9;
% Apply the second equation to 'kd' where Ph is greater than 0.35
Kd(indices2) = exp(-62.60.*PhiE(indices2)+22.58).*1e9;

댓글 수: 2

Dyuman Joshi
Dyuman Joshi 2024년 3월 5일
"Have I done it correctly?"
Yes. Your code looks good.
Nisar Ahmed
Nisar Ahmed 2025년 2월 4일
이동: Dyuman Joshi 2025년 9월 13일
Thanks

댓글을 달려면 로그인하십시오.

답변 (1개)

Karan Singh
Karan Singh 2025년 1월 31일

1 개 추천

Hi Ahmed,
Everything seems to be in order here. The code you provided has a typo in the second equation where you mistakenly used "PhiE" instead of "Ph." Is "PhiE" something different? Otherwise, everything seems fine. Your use of ".*" and ".^" is correct for element-wise operations, which is necessary given that "Ph" is an array.

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2024년 3월 5일

이동:

2025년 9월 13일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by