Unrecognized function or variable 'size'. in function called from script
이전 댓글 표시
The Problem:
I have a script, where I call two self-written functions. One of the functions is called weightingFkt2(). In this function I call the find() function of Matlab, which returns indexes. Now, if I want to call indexsize=size(index,2) I get an error "Unrecognized function or variable 'size'." while running the code.
What I have already done (besides researching):
I checked in the weightedFkt(), if it is a matrix. It is.
If I write the same line (indexsize=size(index,2);) in the command window after getting the error (I told matlab to pause on errors) it works fine.
I got the same error on different variables in the same function before. There I was able to put the call of size() into the script, where it worked fine.
I use Matlab R2019b.
The relevant lines of code in the functioin I attach, the line where I get the error is line 43, the lines where I got errors, but was able to put the line in the script are 5,6 and 17.
In the script the relevant lines of codes are:
origsize1=size(origimage,1);
origsize2=size(origimage,2);
newsize1=round(origsize1*1.25);
newsize2=round(origsize2*1.25);
for x=1:newsize1
for y=1:newsize2
%findnearestindeces: finds the nearest points in valuepixels
%of x and y
nearestindex=findnearestindeces(x,y,valuepixels(:,:,:)); %valuepixels: valuepixels(s,t,:)=[currentPoint(1), currentPoint(2), neworigimage(s,t)];
size3=size(nearestindex,1); %due to error message in weightingFkt() now in script
cp=[x y];
imagevalue=weightingFkt2(nearestindex, cp, valuepixels, size3);
finalimage(x,y)=imagevalue;
end
end
So my question is, how I can solve that.
As that is my first question in this forum I tried to follow all the guidelines and add all the relevant code but please let me know, if something is missing.
댓글 수: 2
Walter Roberson
2021년 8월 18일
I wonder if the error is against nearestindex instead of against size? If length1 < 1 then you never assign to nearestindex
Katharina Heitger
2021년 8월 18일
채택된 답변
추가 답변 (1개)
Most likely, somewhere in your code you use "size" as a varibale name. Try "debstop error"; When error occurs, use "whos" to see if "size" is in the variable list.
댓글 수: 8
Katharina Heitger
2021년 8월 18일
Chunru
2021년 8월 18일
Provide more details of the error messages (where it goes wrong). It's even better if you can provide executable code that demonstrate the error.
Katharina Heitger
2021년 8월 19일
Walter Roberson
2021년 8월 19일
편집: Walter Roberson
2021년 8월 19일
In the code, just before the error, try
which size(index,2)
also, I suggest taking the code and copying the function name directly from the code (using your mouse), and then at the command window do
'size'+0
except copying from the code into the command. The purpose of this would be to check that there are no special characters, no mistaken spelling that is being overlooked
Question: does your code just happen to assign to a variable named path ? If so, then Don't Do That.
Katharina Heitger
2021년 8월 19일
Katharina Heitger
2021년 8월 19일
Katharina Heitger
2021년 8월 19일
Katharina Heitger
2021년 8월 19일
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!