MATLAB Fun​ction ブロック​の使い方について

12 views (last 30 days)
O.E
O.E on 22 Jun 2018
Commented: O.E on 24 Jun 2018
以下のFunctionをMATLABFunctionとして実装したいと考えています。
このとき計算の結果をyとして出力したいと思うのですが出力yの値が反映されずエラーが出てしまいます。
どのようにすれば解決しますか
エラー内容
関数または変数 'y' が未定義です。ローカル変数への 1 番目の代入は、そのクラスを特定します。
function y = A (u,a,b)
al = u; % input signal [V]
s = a; % bit
F = b; % [V]
L_v = F/2;
for m=1:1:s
if m == 1
Vth = 0;
y(1) = ( sign(al) + 1 ) / 2;
end
if m ~= 1
y(m) = ( sign (al - m ) + 1 ) / 2 ;
end
end

Accepted Answer

Hiroumi Mita
Hiroumi Mita on 22 Jun 2018
yの配列を確保するため、次のようにソースを変更してもらい、 あとは状況に応じ出てくるエラーをつぶしてください。
function y = A (u,a,b)
al = u; % input signal [V]
s = a; % bit
F = b; % [V]
L_v = F/2;
y=zeros(s,1);%配列確保<-ココ!!
for m=1:1:s
if m == 1
Vth = 0;
y(1) = ( sign(al) + 1 ) / 2;
end
if m ~= 1
y(m) = ( sign (al - m ) + 1 ) / 2 ;
end
end
  1 Comment
O.E
O.E on 24 Jun 2018
解決いたしました。ありがとうございます。

Sign in to comment.

More Answers (0)

Categories

Find more on Author Block Algorithms in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!