# How to put a condition for equations in the computation

2 ビュー (過去 30 日間)
Nisar Ahmed 2022 年 7 月 3 日
コメント済み: Nisar Ahmed 2022 年 7 月 4 日
Hi
I have attached a data 'al' varies from say 0.05 to 0.32.
I want calculate d from al, but there are two equations for the d based on al values, like
if al>0.15 then, d = 38.18.*(1-3.39.*p+1.95.*al.^2); (eq 1)
if al>0.15 then d = 33.18.*(1-2.39.*p+1.05.*al.^2); (eq 2)
How I can put this condition in my code that if al>0.15 use equation 1 and otherwise eq 2. and a final d = 115*1.
##### 1 件のコメント-1 件の古いコメントを表示-1 件の古いコメントを非表示
Nisar Ahmed 2022 年 7 月 4 日
@Carter Sorensen Thanks dear

サインインしてコメントする。

### 採用された回答

Carter Sorensen 2022 年 7 月 3 日

Hi Nisar,
I may be misunderstanding your question, so please let me know if my response is not what you were looking for.
You could use a simple for-loop to cycle through the different values in 'al'. Within the for-loop, an if-else statement could check whether 'al' is > 0.15 and then compute the appropriate 'd'. Below is an example (note, I assumed a 'p' value):
p = 1; % Assumed 'p'
for i = 1:length(al) % Cycles through 'al' values
if al(i) > 0.15 % Checks first condition
d(i) = 38.18.*(1-3.39.*p+1.95.*al(i).^2); % Computes 'd' if first condition met
else
d(i) = 33.18.*(1-2.39.*p+1.05.*al(i).^2);
end
end
The result is stored in a 115x1 matrix called 'd'.

サインインしてコメントする。

### カテゴリ

Help Center および File ExchangeLanguage Fundamentals についてさらに検索

### Community Treasure Hunt

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

Start Hunting!