How do I plot a function with multiple outputs?

2 visualizaciones (últimos 30 días)
Gabriel
Gabriel el 30 de Jul. de 2022
Comentada: Gabriel el 30 de Jul. de 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.

Respuesta aceptada

Dyuman Joshi
Dyuman Joshi el 30 de Jul. de 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 comentarios
Dyuman Joshi
Dyuman Joshi el 30 de Jul. de 2022
Editada: Dyuman Joshi el 30 de Jul. de 2022
%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 el 30 de Jul. de 2022
Thanks again!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Graphics Performance en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by