Storing the absor function into my code gives ABSURD error

Hi all
I was trying to store the absor function in my code, to avoid calling it from a separate m file. Strangely it worked fine as a separate m file but as soon as copying it into my code, It seems that matlab doesn't like it's last three functions and says they might not be used. when I try to run the code, it gives the error on dealr function.
Error: Undefined function 'dealr' for input arguments of type 'double'.
I still have not changed the way I use the absor function in the code as I wrote when I was calling it as an external mfile :
[regParams,Bfit,ErrorStats]=absor(A1,A2);
I don't know whether I should introduce
funx= @absor
and if so, how to change the function expression and still : what is that error , and if the function is not actually dealr but deal and there is a typo in the function name
but still : why was it working fine as a separate m file ?

 采纳的回答

You need to close all your functions with the end keyword or none of them. Within the same file you cannot mix the two styles. My guess is that the file you pasted this in did already use end keywords for each function, and this absor function doesn't.

7 个评论

Thank you , that was a good hint, but I tried both cases . in case I remove all function ends
I have :
All functions in a script must be closed with an 'end'.
and if I put all the ends, I get the above error
Can you attach the file without the absor pasted in?
Dear Rik, very sorry if I can't share my code here, is it possible to help me out by telling me what to check?
Dear Rik , the reason I believe the problem is with the absor code is that I put another function before absor in the end of my code and matlab asked me to put an end for that function and it works fine. but just after putting the absor after the end of the first function, these problems arise.
I believe you can try it on any arbitrary code and you will get the same problem
The file should look something like this:
function yourfunction
%code
end
function [regParams,Bfit,ErrorStats]=absor(A,B,varargin)
%code
end
function M=matmvecHandle(M,v)
%code
end
function M=mattvecHandle(M,v)
%code
end
function varargout=dealr(v)
%code
end
If you're using R2016b or newer, your main function is allowed to be a script, otherwise you need to make it a function as well.
You are mistaken, farzad.
I put the following code into a script:
N = 10;
A = randn(2, N);
B = randn(2, N);
[regParams,Bfit,ErrorStats]=absor(A,B);
disp(regParams)
disp(Bfit)
disp(ErrorStats)
followed by the code for absor taken from the File Exchange, except that I added an end statement corresponding to every function statement. The results looked fine to me.
Note that you have four functions for which end must be added.
You are right Walter ! Thank you so much Rik ! the problem was the structure of where to write the end !
I was accumulating the 4 ends at the bottom of the scripts not right after each function

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by