I have the following piecewise function that I want to use, but I need to send a vector to it. When I try to send the vector, it does not perform the piecewise function based on the condidtions and instead sends back a vector of the calcuation all for the same condition. How can I write this so that I can send the vector for it to come back as I want it based on the conditions?
function value=IC1_wave_func1(x)
if x < .25
value = x/25;
else
value = .015-x/50;
end
end

1 件のコメント

madhan ravi
madhan ravi 2020 年 6 月 3 日
Show your effort to get response.

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

 採用された回答

Kevin Cottrell
Kevin Cottrell 2020 年 6 月 3 日

1 投票

Its not the prettiest and there's definitly better ways to do it but i decided to send it through a while loop and go peice by peice through the vector.
function value=IC1_wave_func1(x)
count = 1;
size = numel(x);
while count < size+1
mid1 = x(count)/25;
mid2 = .015-x(count)/50;
if (mid1 > mid2)
value(count) = mid2;
else
value(count) = mid1;
end
count = count+1;
end
end

その他の回答 (1 件)

madhan ravi
madhan ravi 2020 年 6 月 3 日

0 投票

doc piecewise

1 件のコメント

Kevin Cottrell
Kevin Cottrell 2020 年 6 月 3 日
I have looked at this and I have tried using it, but it keeps returning with "Check for missing argument or incorrect argument data type in call to function 'piecewise'."
function value=IC1_wave_func1(x)
value(x) = piecewise(x<.25, x/25, x>=.25, .015-x/50);
end

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

カテゴリ

ヘルプ センター および File ExchangeApplication Deployment についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by