필터 지우기
필터 지우기

Error in a user-define function calling.

조회 수: 2 (최근 30일)
Aftab Ahmed Khan
Aftab Ahmed Khan 2014년 6월 7일
댓글: Star Strider 2014년 6월 7일
Hi, i am returning multiple values from a user-function but this gives an error of Too many output arguments , i don't know where i am making the mistake ?
This is my function calling inside the loop,
for i = 1:no_users
[indexes(:,i), users_data(i,:)] = singleuser_traffic(num_event);
end
And this is the first line of the user-function
function [index, sort_user1] = singleuser_traffic(num_event)
I can't see any mistake in my function call, Thank you so much

채택된 답변

Star Strider
Star Strider 2014년 6월 7일
Providing you’re not using the ‘index’ and ‘sort_user1’ variables elsewhere, try:
for i = 1:no_users
[index, sort_user1] = singleuser_traffic(num_event);
indexes(:,i) = index;
users_data(i,:) = sort_user1;
end
This doesn’t significantly add to the overload, and will let you see what the incompatibility is between what the function returns and what you want in your ‘indices’ and ‘users_data’ arrays.
I’ve found that for whatever reason, most functions will crash if you ask them to fill arrays for you. Let them return what they want, and do the array assignments just after.
BTW, num_event isn’t subscripted in your loop, so unless you’re defining it to change outside the loop you posted, you’re giving it the same argument in each iteration.
  댓글 수: 7
Aftab Ahmed Khan
Aftab Ahmed Khan 2014년 6월 7일
Hi,
You won't believe this that i was making changes in my function-file which was placed in another folder and was calling another function with the same name placed placed in the current directory..................
Thanks life saver..........
Star Strider
Star Strider 2014년 6월 7일
My pleasure!
I’ve done that as well. If I’m working on one file to improve it and am using the previous version of it, I temporarily put a ‘#’ at the end of the file name of the version I don’t want to run. I remove the ‘#’ when I want to test the new version. I do my best to keep them in the same directory so that I don’t lose track of them.
Another helpful feature is the which function:
which singleuser_traffic -all
can be revealing in any situation where you believe a function isn’t behaving correctly.

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

추가 답변 (1개)

Image Analyst
Image Analyst 2014년 6월 7일
Before you call it, check out the size of indexes and users_data.
Inside the function, check the size of index and sort_user1.
Chances are they have different numbers of rows or index and sort_user1 are row vectors instead column vectors.
  댓글 수: 1
Aftab Ahmed Khan
Aftab Ahmed Khan 2014년 6월 7일
Hi, Thank you for the reply.
For each loop iteration, index variable produce a 500*1 column vector whihle the sort_user1 produce a 1*500 row vector.
I think my function calling is set according to this situation, isn't it ?

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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by