Indexing cannot yield multiple results matlab

i have my function like this;
when i run the the program it gives; Indexing cannot yield multiple results.Error in [Edump,Eb,Ech] = charge(Phkt,Pw,Pp,Ebmax,uinv,Pl,t,PchE,dump,Eb,Ech)
if true
% code
end
function [Edump,Eb,Ech] = charge(Phkt,Pw,Pp,Ebmax,uinv,Pl,t,PchE,dump,Eb,Ech)
global Phkt Pw Pp Eb Ebmax uinv Pl t Ech
% CHARGE
Pch(t)=( Pp(t)+Pw(t)+Phkt(t))-(Pl(t)/uinv);
Ech(t)=Pch(t);%*1;%one hour iteration time
if Ech(t)<=Ebmax-Eb(t)
Eb(t)=Eb(t-1)+Ech(t);
if Eb(t)>Ebmax
Eb(t)=Ebmax;
Edump(t)=Ech(t)-(Ebmax-Eb(t));
else
Edump(t)=0;
end
return
else
Eb(t)=Ebmax;
Edump(t)=Ech(t)-(Ebmax-Eb(t));
return
end
end
[Edump,Eb,Ech] = charge(Pp,Pw,Phkt,Eb,Ebmax,uinv,Pl,t,Edump,Ech);

2 comentarios

Star Strider
Star Strider el 24 de Dic. de 2016
What arguments (and their sizes and classes) are you passing to your ‘charge’ function?
Tahir Ibitoye
Tahir Ibitoye el 5 de En. de 2017
I don't get you.... Can you please explain what you are trying to say? I'm not that vast in the use of MATLAB

Iniciar sesión para comentar.

 Respuesta aceptada

Adam
Adam el 5 de En. de 2017
Why on earth are you declaring a bunch of global variables of the same names as many that you are passing into your function? At best this will do nothing, at worst it will have all kinds of unwanted effects that could cause a load of obscure bugs.
The error you are getting though suggests that when you call
[Edump,Eb,Ech] = charge(Phkt,Pw,Pp,Ebmax,uinv,Pl,t,PchE,dump,Eb,Ech)
Matlab thinks 'charge' is a variable that it is indexing into rather than a function that it is calling. So first thing to check is where you call it do you have a variable called 'charge' also? If so then this is the problem (or at least the problem causing the error you give).

Más respuestas (0)

Categorías

Preguntada:

el 24 de Dic. de 2016

Respondida:

el 5 de En. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by