How do I plot a function with multiple outputs?
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Gabriel
am 30 Jul. 2022
Kommentiert: Gabriel
am 30 Jul. 2022
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.
0 Kommentare
Akzeptierte Antwort
Dyuman Joshi
am 30 Jul. 2022
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 Kommentare
Dyuman Joshi
am 30 Jul. 2022
Bearbeitet: Dyuman Joshi
am 30 Jul. 2022
%y limit
ylim([0 1])
%color
plot(VVectA3, 'r')
plot(VVectB3, 'b')
plot(VVectA3+VVectB3, 'k')
You can choose color of your choice
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
