필터 지우기
필터 지우기

Indexing cannot yield multiple results error

조회 수: 7 (최근 30일)
Joao
Joao 2014년 10월 27일
편집: Stephen23 2016년 2월 6일
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
Joao
Joao 2014년 10월 27일
Yes i had another variable called coupler. Many thanks!!
Adam
Adam 2014년 10월 27일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Adam
Adam 2014년 10월 27일
편집: Adam 2014년 10월 27일
Check that you do not also have a variable called 'coupler' which will stop Matlab from being able to see your function.
If you have a variable, 'coupler', then the line:
[E11x,E22x] = coupler(Eaf1,Ebf1,Npt);
will attempt to index into that variable, rather than calling your function, which will result in the error you showed as indexing into a variable cannot return two outputs.
As Star Strider points out, you can type:
which coupler -all
to check if you have a variable called 'coupler'. If you get a variable returned here as well as your function then that is the problem.
  댓글 수: 1
Star Strider
Star Strider 2014년 10월 27일
Joao replied:
‘Yes i had another variable called coupler. Many thanks!!’

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

BHANESH BHADRECHA
BHANESH BHADRECHA 2016년 2월 6일
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

카테고리

Help CenterFile Exchange에서 Historical Contests에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by