Conflict between native and toolbox function

I've an issue running a script which used to run fine in previous version of MATLAB (R2017a). Now I'm on R2019a.
This script uses a scroll function defined in a different toolbox than the native one (the error I get comes from this function, see below).
Dot indexing is not supported for variables of this type.
Error in matlab.ui.internal.mixin.Scrollable/scroll
Error in pop_prop_extended (line 210)
scroll(EEG.times, single(icaacttmp), 5, EEG.event, fh, datax, scrollax);
I've checked path defintion and the folder in which I have the function I want to use is well before the built-in one.
Here is what I get when I prompt the which command:
which -all scroll
C:\Users\Alexandre\Desktop\code\eeglab14_1_0b\plugins\Viewprops1.5\scroll.m
C:\Program Files\MATLAB\R2019a\toolbox\matlab\uicomponents\uicomponents\+matlab\+ui\+internal\+mixin\@Scrollable\scroll.p % Shadowed matlab.ui.Figure method
What does the 'Shadowed matlab.ui.Figure method' comment mean? Does it overrule the function I want to use anyway?

 Accepted Answer

You can add the path where the scroll.m file is located to the MATLAB search path permanently by using savepath function. Then MATLAB will run the scroll.m file that is defined by you over the built-in function.
Refer the following answer that explains how to add the user-defined path to the MATLAB search path.
Please refer to the following documentation for the function precedence order in MATLAB.
Edit : In the above case, scroll is an object function and it takes precedence over the user defined function. I suggest you to use package.
You can create a folder named +mypack and add this file inside.
Later you can import the file using the command
import mypack.*
This overrides all others since it is second in the precedence order. Only variable names takes more precedence than this.

5 Comments

The toolbox-defined function is already permanently added to my path, and I checked it was always before the built-in function in the search path...
Thank you for the precedence documentation, this is really helpful to understand how Matlab deals with such case. If I understand the documentation correctly, the built-in function seems to prevail anyway because it is located in an @ folder?
In the end, I think the simplest solution for me is to edit the toolbox-defined function name to avoid the conflict.
If you look at the 10th and 11th point in the precedence document, functions in the current folder take preference over functions in other MATLAB search path.
Once MATLAB could not find the function in the current folder, MATLAB search for the function in the search path. You can issue the command
path
to see the order in which MATLAB searches for any function.
If you add the path
C:\Users\Alexandre\Desktop\code\eeglab14_1_0b\plugins\Viewprops1.5\
to the search path list, then MATLAB run the scroll.m defined in the above-mentioned path
I understand what your explanation but in my case I think the 8th precedence point applies since the built-in function is found in a folder named ...\@Scrollable\. But I may be mistaken since I've never worked explicitely with objects and classes in Matlab yet.
When I issue the command path just before I call scroll (stopped with debugger), the folder C:\Users\Alexandre\Desktop\code\eeglab14_1_0b\plugins\Viewprops1.5 appears before C:\Program Files\MATLAB\R2019a\toolbox\matlab\uicomponents\uicomponents and I still get the error I mentionned in the first place.
My current folder is C:\Users\Alexandre\Desktop\code may it be important to precise.
If you think my interpretation of the precedence order is wrong please tell me, I really want to understand the origin of the issue here.
I am mistaken in the above analysis. Here the inbuilt scroll.m took precedence in your case because it is an object function (Precedence 7 in the document). scroll if you go through the document takes class objects like Figure, GridLayout as argument.
Thanks! It's clearer now!

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2019a

Community Treasure Hunt

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

Start Hunting!