From: us on
"Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <hsjme5$d8h$1(a)fred.mathworks.com>...
> Dear Niccolo!
>
> > I've realized I've to do it harder: I should break a loop generated by a p-file. I'm using an optimization algorithm and a nuber is close to singular or bad scaled. since I've no access to the p-file, can I give a command before calling the p-file for breaking from that loop once a waring is encountered?
>
> P-files can be easily influenced by creating M-files with the called subfunctions in the same directory. So if your warning is created e.g. in the function LU, create a new file called "lu.m" in the same directory as your P-file:
>
> ----------------------------------------
> % Please adjust the number of outputs etc to your special problem.
> function [L, U, P, Q] = lu(varargin)
> [L, U, P, Q] = builtin('lu', varargin{:});
> if ~isempty(lastwarn)
> error(lastwarn);
> end
> -----------------------------------------
>
> Then you can enclose the call to your optimization in a TRY CATCH block.
> Use this to find the function which causes the warning:
> dbstop if warning
>
> Good luck, Jan

good stuff... yet, it does not completely solve the OP's problem as he/she still does not get access to the built-in...

us
From: Niccolo' Bulgarini on
another problem is that I receive this message:

Warning: Matrix is singular to working precision.
> In /home ... optim/optim/private/backsolveSys.p>backsolveSys at 11
In /home ...optim/optim/private/solveKKTsystem.p>solveKKTsystem at 9
In /home ...optim/optim/private/computeTrialStep.p>computeTrialStep at 60
In /home ...optim/optim/barrier.p>barrier at 275

so I don't know neither which input & output arguments has the backsolveSys.p function!




"us " <us(a)neurol.unizh.ch> wrote in message <hsjnp8$btk$1(a)fred.mathworks.com>...
> "Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <hsjme5$d8h$1(a)fred.mathworks.com>...
> > Dear Niccolo!
> >
> > > I've realized I've to do it harder: I should break a loop generated by a p-file. I'm using an optimization algorithm and a nuber is close to singular or bad scaled. since I've no access to the p-file, can I give a command before calling the p-file for breaking from that loop once a waring is encountered?
> >
> > P-files can be easily influenced by creating M-files with the called subfunctions in the same directory. So if your warning is created e.g. in the function LU, create a new file called "lu.m" in the same directory as your P-file:
> >
> > ----------------------------------------
> > % Please adjust the number of outputs etc to your special problem.
> > function [L, U, P, Q] = lu(varargin)
> > [L, U, P, Q] = builtin('lu', varargin{:});
> > if ~isempty(lastwarn)
> > error(lastwarn);
> > end
> > -----------------------------------------
> >
> > Then you can enclose the call to your optimization in a TRY CATCH block.
> > Use this to find the function which causes the warning:
> > dbstop if warning
> >
> > Good luck, Jan
>
> good stuff... yet, it does not completely solve the OP's problem as he/she still does not get access to the built-in...
>
> us
From: Jan Simon on
Dear Urs!

> > P-files can be easily influenced by creating M-files with the called subfunctions in the same directory. So if your warning is created e.g. in the function LU, create a new file called "lu.m" in the same directory as your P-file:
> >
> > ----------------------------------------
> > % Please adjust the number of outputs etc to your special problem.
> > function [L, U, P, Q] = lu(varargin)
> > [L, U, P, Q] = builtin('lu', varargin{:});
> > if ~isempty(lastwarn)
> > error(lastwarn);
> > end
> > -----------------------------------------
> >
> > Then you can enclose the call to your optimization in a TRY CATCH block.
> > Use this to find the function which causes the warning:
> > dbstop if warning
> >
> > Good luck, Jan

> good stuff... yet, it does not completely solve the OP's problem as he/she still does not get access to the built-in...
>
> us

Correct! Damn, I'm still thinking in Matlab 6.5, where built-in's are called instead of functions in the local directory.

For Matlab 2009a I find this behaviour:
I create test.m in a folder in the Matlab path:
% File D:\MFiles\test.m --------------------
function [L, U] = test(X)
which('lu')
[L, U] = lu(X);
% --------------------

% File D:\MFiles\lu.m --------------------
function [L, U] = lu(X)
disp('my lu')
[L, U] = builtin('lu', X);
% ---------------------

The WHICH command replies correctly:
D:\MFiles\lu.m
but it does not call the local lu! "my lu" does not appear in the command window. When I make this folder the current directory, a warning appears, that "the same name exists as a MATLAB builtin". But my local lu is not called neither after cd('D:\MFiles') nor after cd(elsewhere).
Moving D:\MFiles to the initial position in the path does not help.
This is conform with the documentation, because lu is an overloaded function for @double and @single, and overloaded function have the precedence 5, M-files in the current directory come at position 6, and M-files on the path and built-in's at the last position 7.

E.g. STRCMP in the same folder *is* called instead of Matlab's builtin function. If you create a @char/strcmp.m anywhere in the path, then the local STRCMP is not called anymore!

Then I tried moving the personal lu to the subfolder D:\MFiles\private\ and it works as expected and wanted: "test" calls \private\lu, \private\lu calls built-in lu. Private functions have the precedence 3...
This private\ method allows bypassing all functions (except for the 20 keywords - see ISKEYWORD) called by P-files and this is the cause for the very limited privacy/security level of the P-coding.

@OP: Please create the man-in-the-middle-attack function in a the subfolder private\ . Or ask the author to ship the M-file.

Jan