Indexing cannot yield multiple results error
Ältere Kommentare anzeigen
Hello! I have this function:
function [E1x,E2x]=coupler(Eax,Ebx,Npt1)
n=1;
Eout=zeros(Npt1,2);
E1x=zeros(Npt1,1);
E2x=zeros(Npt1,1);
while n<=Npt1
Enew=[Eax(n); Ebx(n)];
c=[sqrt(0.5) 1i*sqrt(0.5);1i*sqrt(0.5) sqrt(0.5)];
Eout(n,:)=c*Enew;
E1x(n)=Eout(n,1);
E2x(n)=Eout(n,2);
n=n+1;
end
end
I am calling this function like this:
[E11x,E22x] = coupler(Eaf1,Ebf1,Npt);
However the error appears: Indexing cannot yield multiple results. What am I doing wrong?
Best regards, João
4 Kommentare
Adam
am 27 Okt. 2014
Please use the {} Code block, selecting all your code first and clicking it, for more readable formatting.
Does the error tell you which line is causing the problem or have you stepped through the code to determine which line?
I can't see anything at a glance that would cause that error unless you have a variable called 'coupler' in which case the error would make sense as trying to index into a variable cannot give two outputs in the line:
[E11x,E22x] = coupler(Eaf1,Ebf1,Npt);
so make sure you do not have a variable stamping on your function name.
Star Strider
am 27 Okt. 2014
...and the best way to detect that possibility is to type:
which coupler -all
in the Command Window. Your function should be the only result you get.
Joao
am 27 Okt. 2014
Adam
am 27 Okt. 2014
I'll add it as an answer then in case anyone comes to this thread in future with the same problem. I didn't want to put it as an answer first since I wasn't 100% sure if that was the problem.
Akzeptierte Antwort
Weitere Antworten (1)
BHANESH BHADRECHA
am 6 Feb. 2016
0 Stimmen
That is because you have created any loop and in that loop variable is changing its value every time loop executes.
The best way is to clear variables that are defined in that loop.
clear this variables before the loop ends.....
for example
for i=1:1000 j=stft(x); k=max(j); clear j; clear k; end
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!