How do I plot a function with multiple outputs?

조회 수: 16 (최근 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 CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by