Where is "Go to definition" Feature! Navigating objects and methods in MATLAB

I have a lot of classes and methods in my project. I've been putting up with the lack of "Go to definition" feature/aka Ctrl+click (along with Alt+left and right to navigate back and forth) only because of MATLAB'S speed (It is blazing fast! Even C++ Armadillo can't catch up). However, I'm not sure if it is feasible for long-term algorithm development (+ object-oriented code) without this feature.
Other IDEs like PyCharm, CLion, and Visual Studios all have this, and it makes developing/refactoring code so much more efficient and easier.
Has anyone found a solution for this? Or, is this the price I have to pay to use MATLAB? I've found out about VS Code MATLAB plugin and it is quite great with the colors and all but the "Go to definition" doesn't work for methods.
I've tested the same algorithm with Python+Numpy and it is about 2x slower but it is free and the IDE really accelerates the code development time beyond 2x, so maybe, I'll just have to move to Python?

Answers (1)

  1. Right click in the function you want to go to the source code of. Then select "Open thatFunctionName".
  2. Or click in the function name and type control-D.
Not sure about with the VS Code plugin because I don't use that.

8 Comments

I'm not using functions. Everything is a method under some objects. The thing we're modeling really plays nicely with OOP and FP is no longer an option.
It will open methods of a class also. Essentially methods of a class are functions.
Hmm, it doesn't for me for methods. I can click on Yes below and it'll create an empty file, which doesn't help anyone. It will open for pure functions with no issues tho.
What version of MATLAB are you talking about? Mine is 2019b.
Are you sure correct_hde is a method and not a property? Also is "c:......hde_cal" on the search path or in the current folder? It's worked for all versions I've ever used going back to 2006. I'm using R2022a now.
I tried it now with one of my methods on a static class and it went directly to the source code for that method.
Yeah they are all in the same folder.
So, I just found out something. I am pretty sure you have named the variable that contains the instance of the object the same name as the object. E.g.
But if I do, someClass1 = someClass(1,1); ctrl+D doesn't work. It's always looking for someClass.method1 and it is not smart enough to know the connection if the instance variable name is not the same as the class name. I guess if I'm ever going to have only one instance of the object, I can abuse this but it is definitely not right.
Please let me know if that's how you're instantiating your objects.
To reiterate, a script like below will run and works as expected but you cannot use Ctrl+D on method1.
This is definitely a bug if it hasn't been fixed in later MATLAB versions.
If I do this:
e = Excel_utils;
b = e.ActivateSheet
and click somewhere in ActivateSheet, then it won't work UNTIL I run the program. Reason being that the "e" variable does not exist if I'm just not running the program and am just editing. There is no "e" variable yet (while editing) so of course the ActivateSheet method of that (non-existent) class does not either.
Now, if I do
e = Excel_utils.ActivateSheet;
then that works because Excel_utils is not an instance/object - it's a static class.
However if I run the code and put a breakpoint on the b= line of code then I CAN go into the ActivateSheet source code because by that time, the e object has been created, and this ActivateSheet method will be a part of that object.
I see... Thanks for the explanation. I tried what you mentioned (running once first before) and it is still not working.
I believe it is because I'm instantiating with the parenthesis someClass1 = someClass(1,1) because it is not a static class like Excel_utils. The objects we're modeling need to have both state and behavior.

Sign in to comment.

Categories

Products

Release

R2019b

Asked:

on 29 Aug 2022

Commented:

on 29 Aug 2022

Community Treasure Hunt

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

Start Hunting!