FreeMat alternative to MatLab's findobj() - matlab

Is there an equivalent function in FreeMat? I can't seem to find one and the documentation is poorly organised.
Any recommendations for work-arounds?

I am not sure if that helps, but I am not using this function in Matlab either. I always organise my objects in a list that is either stored in a global workspace or passed around other to objects.
So what you could do is create an Object like a list that has a search and add function. Put it in global scope and make it a singleton (I know, friends don't let friends write singletons). This way you can find all you add to this list easily.
You might want to check out the "service locator" pattern: https://en.wikipedia.org/wiki/Service_locator_pattern
I think the findobj() function in MATLAB does someting similar.

Related

All usages of a variable/parameter in anylogic

Is there an easy way to figure out all places where a variable or parameter is being utilised in annylogic. Trying to locate where each variable is used can be a pain during debugging.
Sure. Just "ignore" it in the properties and compile the model.
You will get a list of errors for all places where it is called. Double-click on each error and AnyLogic even takes you there :)
Else, you can also use the AnyLogic search functionality.
in order to get some relief for that pain if your model is too big, all your variables should be private and you create setters, so each time you change your variable, you required to use a set function.
This doesn't solve your question, but it tells you what to do in future models to make it easier for you
check this video
https://www.youtube.com/watch?v=gNBfdB6YF7o

Documentation of OCaml code in Eclipse

I'm using Eclipse with the OcaIDE-Plugin to write my ocaml-project.
I have written several ocaml-functions that I want to document (comment, return values and params).
I've created my documentation in the .ml-files like described in this link: http://caml.inria.fr/pub/docs/manual-ocaml/ocamldoc.html
Here is an example of one function:
(** sorting tuples where first element is key *)
let my_comp x y = (*Some code*)
Unfortunately, my comments don't show up, when I press F2 at one of the functions, it only shows the name and the file it is contained.
When writing comments in an mli-file, it works as expected, but i also want to document "private" functions that are not accessible from the outside. Can I define functions in the mli, that are NOT accessible from the outside, just for the documentation?
How can I make Eclipse to show my documention?
Well, as you said, you would like to show the documentation but not export the function out of the module. That, sadly, won't work.
I guess OcaIDE can be considered as incomplete but it doesn't look like it's something people care about (I don't know a single person working on OcaIDE). If you like having autocompletion etc, maybe try to program with emacs and install merlin (look, I found the perfect post for you : here)
As for the suggestion of defining a function in the mli not accessible from the outside, it's completely opposed to why mli files are created, so don't expect that to be possible. ;-)
I hoped I've been able to help you.

Function Fields Feature in Matlab

mapminmax is a builtin Matlab function. I am trying to implement something that does autocomplete for functions/subfunctions like this.
I've done a quick search but haven't really come up with what it's called. mapminmax is the only function I know of that implements this feature. It looks like a field of a function (like how a field of a struct).
I've used edit mapminmax to see the insides of Matlab's function but I haven't found anything leading to how this is possible. getParamStructFromArgs looks like it might be able to explain what this is, but it looks like it's related to NNs.
Question: What is this feature called and is there any documentation on this?
Looks like what #hypfco said was right. This "feature" is related to Matlab's package system. I'm sure there's a way to do it by creating a package, but for those who don't want to create such a package there's a simple way of doing this.
If you have a function such as untitled.m, you can create a folder called +untitled in your Matlab directory.
Function's .m file
+Function folder
Then when you do untitled. and press tab in the console, you'll get the following pop-up.
If anyone's got a way to do this inside the .m file, I'll accept that answer instead.

Matlab: How to return output from a function in a set()?

I am now using Matlab GUI and have problem during accessing return values from a function which is set by set().
Situation:
I set the windowMotionFcn as below:
set(gcf,'WindowButtonMotionFcn',#test);
Function 'test' can return 2 variables (named as var1 and var2).But I dont know how to store them...
I have searched in the Internet and could not find any way.
How should I write?
Thank you for your help and kind attention.
I think that what you want to do is to return a value from the callback function. And regarding returning a value from a callback I am not sure that is possible. I found an old article from matlab newsreader. I think your problem could be similar.
However, if you have a matlab GUIDE GUI, there is a way to return a value from a gui. It is described in a matlab tutorial in matlab central: advanced-getting-an-output-from-a-guide-gui. What you must do is to modify your CloseRequestFcn and your OutputFcn.
Another way, which should work is using global variables. A global varable exist in the global workspace. That means that it can be seen and accessed by every function in matlab. Global variables are in most cases not recommended, but if no other solution exists they may be necessary. Just make sure to document them, so that the next person to take over your code knows that they are there. Also make sure to select a good name for the globals, like gblMyVar so there can be no confusion that the variable is global.

Find indirect calls to specific built-in MATLAB function

What do I want?
I am looking for a way to detect all points in my code where a specific function is called.
Why do I want it?
Some examples:
Some output comes out sorted or randomized, and I want to know where this happens
I am considering to change/overload a function and want to know in which part of my code this could have impact
What have I tried?
I tried placing a breakpoint in the file that was called. This only works for non builtin functions which are called from short running code that always executes everything.
I tried 'find files', this way I can easily find direct calls to sort but it is not so easy to find a call to sort invoked by unique for example.
I have tried depfun, it tells me:
whether something will be called
from where non-builtin functions will be called
I thought of overloading the builtin function, but feels like a last resort for me as I am afraid to make a mess. | Edit: Also it probably won't help due to function precedence.
The question
What is the best way to track all potential (in)direct function calls from a specific function to a specific (built-in)function.
I don't exactly understand your use case, but I guess most of the information you want can be obtained using dbstack, which gives you the call-stack of all the parent functions calling a certain function. I think the easiest way is to overload built-in functions something like this (I tried to overload min):
function varargout = min(varargin)
% print info before function call
disp('Wrapped function called with inputs:')
disp(varargin)
[stack,I] = dbstack();
disp('Call stack:')
for i=1:length(stack)
fprintf('level %i: called from line %i in file %s\n', ...
i, stack(i).line, stack(i).file);
end
% call original function
[varargout{1:nargout}] = builtin('min', varargin{:});
% print info after function call
disp('Result of wrapped function:')
disp(varargout)
I tried to test this, but I could not make it work unfortunately, matlab keeps on using the original function, even after playing a lot with addpath. Not sure what I did wrong there, but I hope this gets you started ...
Built-in functions take precedence over functions in local folder or in path. There are two ways you can overload a built-in for direct calls from your own code. By putting your function in a private folder under the same directory where your other MATLAB functions are. This is easier if you are not already using private folder. You can rename your private folder once you are done investigating.
Another way is to use packages and importing them. You put all your override functions in a folder (e.g. +do_not_use). Then in the function where you suspect built-in calls are made add the line "import do_not_use.*;". This will make calls go to the functions in +do_not_use directory first. Once you are done checking you can use "clear import" to clear all imports. This is not easy to use if you have too many functions and do not know in which function you need to add import.
In addition to this, for each of the function you need to follow Bas Swinckels answer for the function body.
Function precedence order.
Those two methods does not work for indirect calls which are not from your own code. For indirect calls I can only think of one way where you create your own class based on built-in type. For example, if you work only on double precision types, you need to create your own class which inherits from double and override the methods you want to detect. Then pass this class as input to your code. Your code should work fine (assuming you are not using class(x) to decide code paths) since the new class should behave like a double data type. This option will not work if your output data is not created from your input data. See subclassing built-in types.
Did you try depfun?
The doc shows results similar to the ones you request.
doc depfun:
...
[list, builtins, classes, prob_files, prob_sym, eval_strings, called_from, java_classes] = depfun('fun') creates additional cell arrays or structure arrays containing information about any problems with the depfun search and about where the functions in list are invoked. The additional outputs are ...
Looks to me you could just filter the results for your function.
Though need to warn you - usually it takes forever to analyze code.