Calling same function shows index in position 1 exceed array bounds even having same input matrix size?

Hi,
I am getting error in calling the same function with different matrix (of same size).
The function is: All input matrix is of same length.
[rate1] = rate(device,BandWidth,Tx,Power1,fading1,No_power);
[rate2] = rate(device,BandWidth,Tx,Power2,fading2,No_power);
  • Note - If i change function name to rate1 and rate2. It not showing error. Donot Why??????????

 채택된 답변

If you do this:
[rate] = rate(device,BandWidth,Tx,Power1,fading1,No_power);
Then rate is now a variable (the output from the function rate()). And the rate() function can no longer be called by saying rate(whatever). 'whatever' is treated like indexes into the variable rate rather than like inputs to the function rate(). So you may get an error the next time you use rate.
Changing the output variable to rate1 fixes it because the function rate() is not replaced in the workspace by the variable rate.

댓글 수: 6

@Benjamin, I didnot understood clearly. What I understood is I cannot name output variable name same as function name.
For example: if i have run below function, who will i should run
SNR = 0:5:40;
Tx= (10^(-3))*db2pow(SNR);
for i=1:length(SNR)
[r] = rate(device,BandWidth,Tx(i),Power1,fading1,No_power);
ra(1,i) = r;
end
it's also giving me error.
when the loop is running 2nd time, it called the below function and then show index exceed in position 1.
function errorCallback = getExtendedErrorCallback(errorId)
end
Can you please copy the entire text of the error (all the red text) and post it here?
restoredefaultpath
rehash toolboxcache
Do the above commands once .
If the problem with getExtendedErrorCallback goes away, then there is something on your MATLAB path that is interfering with normal processing.
This problem got resolved when i make a new folder, write all the codes in that folder.
Thanks a lot for the help.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2021년 12월 31일

댓글:

2021년 12월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by