How do I plot a function with multiple outputs?

11 ビュー (過去 30 日間)
Gabriel
Gabriel 2022 年 7 月 30 日
コメント済み: Gabriel 2022 年 7 月 30 日
I am trying to create a function that will plot with the following parameters:
[VVectA3,VVectB3] = rwAB(10,0,0,0.3,0.3,1);
figure;
plot(VVectA3)
hold on
plot(VVectB3)
plot(VVectA3+VVectB3)
For my rwAB function this is what I did:
function [VvectA,VvectB]=rwAB(nTrials,VA,VB,alphaA,alphaB,lambda)
VVectA = VA;
VVectB = VB;
for i = 1:nTrials
VA = rwABRule(VA,alphaA,lambda)
VB = rwABRule(VB,alphaA,lambda)
VVectA = [VVectA VA]
VVectB = [VVectB VB];
end
end
Furthermore, for the function rwABRule that is within my rwAB function I did this:
[VA,VB]=rwABRule(VA,VB,alphaA,alphaB,lambda)
function [VA,VB]=rwABRule(VA,VB,alphaA,alphaB,lambda)
VA = VA + alphaA*(lambda-VA)
VB = VA + alphaB*(lambda-VB)
end
However, when I try to plot it I am given these three errors:
Error:
Local function name must be different from the script name.
Error:
VA = rwABRule(VA,alphaA,lambda)
Error:
[VVectA3,VVectB3] = rwAB(10,0,0,0.3,0.3,1)
So I know that there is something wrong with either my rwABRule function or my rwAB function or both but I can not figure out what I am doing wrong. I thought I was creating my function correctly but I guess not. Any help would be greatly appreciated.

採用された回答

Dyuman Joshi
Dyuman Joshi 2022 年 7 月 30 日
You are calling the function rwABRule incorrectly.
Also, there's a spelling mistake in your function call.
[VVectA3,VVectB3] = rwAB(10,0,0,0.3,0.3,1);
figure;
plot(VVectA3)
hold on
plot(VVectB3)
plot(VVectA3+VVectB3)
function [VVectA,VVectB]=rwAB(nTrials,VA,VB,alphaA,alphaB,lambda)
%capital V^
VVectA = VA;
VVectB = VB;
for i = 1:nTrials
[VA,VB] = rwABRule(VA,VB,alphaA,alphaB,lambda);
%corrected function call
VVectA = [VVectA VA];
VVectB = [VVectB VB];
end
end
function [VA,VB]=rwABRule(VA,VB,alphaA,alphaB,lambda)
VA = VA + alphaA*(lambda-VA);
VB = VA + alphaB*(lambda-VB);
end
  6 件のコメント
Dyuman Joshi
Dyuman Joshi 2022 年 7 月 30 日
編集済み: Dyuman Joshi 2022 年 7 月 30 日
%y limit
ylim([0 1])
%color
plot(VVectA3, 'r')
plot(VVectB3, 'b')
plot(VVectA3+VVectB3, 'k')
You can choose color of your choice
Gabriel
Gabriel 2022 年 7 月 30 日
Thanks again!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by