Does any one would know a way of overriding the data tooltip that is shown when hovering over a variable when we are in the Matlab editor ? I have a custom class that is relatively simple and its content could be shown easily in the tool tip, but Matlab insists on saying it is a 1x1 CustomClass, which is nice and all, but it would be more useful if we could make it to show the content of the object in a nice way. Right now, I have to type the name of the variable in the cmd window e.g. when debugging instead of a short hover on the variable name. Nitpicky, but I'd find it interesting ^^
I've tried to dig a bit using undocumented leads on data tooltips, e.g. http://undocumentedmatlab.com/blog/accessing-the-matlab-editor/
http://undocumentedmatlab.com/blog/spicing-up-matlab-uicontrol-tooltips/
But I don't have the final answer, anyone has any ideas ?
The tooltip seems to get its string by using the disp method. Override disp on your class. In the method body, construct your desired string however you want and then call disp on it. In R2012a at least this works for the debugger tooltip.
Note that you'll need to do a clear classes after editing the class to get MATLAB to recognize the overridden disp.
Related
If for example you have acquired a object of type handleplot with expression like below:
handle = plot(t,functoin1 , t , function2 ) ;
Now handle will be an array that contains two elements, handle(1) and handle(2). Now suppose you want to change some properties of one of these objects, like set a LineWidth, change the Color, or the like.
Is there any way in which you can activate auto-completion or suggestions when you type handle(1). (note the memebership operator .)? I am looking for the automatic suggestions that MATLAB provides for member functions in a combobox near the blinking cursor, similar to the way other IDEs provide this feature:
MATLAB's objects support tab completion. After typing handle(1). simply hit tab and you will receive a list of available methods and properties of the graphics object.
If you want more help on a method, you will also get a popup dialog of the method and the accepted input arguments.
If you want to programmatically get a list of properties of an object, you can use properties
properties(t)
If you want a listing of all properties and their values, just use get
get(t)
i use this method ...
for example i'm writing a program in matlab editor and when im want to know the properties of an object just stop coding and run the program , know it's have my object (for example handle) and know i can write the properties(handle) in command window to know the exact properties of handle . as Suever says .
I have tried all possible means to figure out the return type of imshowpair command in MATLAB but I still was not able to find its return type.
I would be very thankful if someone could tell me its return type.
In the future, using class is a very easy way to determine the type of a variable that is returned by a function.
According to the documentation, the output of imshowpair is simply the graphics handle to the image object that is created.
h = imshowpair(rand(10), rand(10));
class(h)
matlab.graphics.primitive.Image
You can use this graphics handle to change the appearance of the displayed image. You can call get(h) to get a list of all properties you can get/set and their current values. The documentation for the image object provides a complete list along with the description of each of these properties.
There are three major ways to do so:
Thanks to the help. By browsing the help page for imshowpair(), which can be found here, you can click on the output h and the hyperlink will show you some infos about it which, in this case, is:
handle to Handle Graphics image object.
Image object, returned as a
handle to the Handle Graphics image object created by imshowpair.
Thanks to the Workspace. In Matlab you can setup your window layout in order to show the Workspace that is a list of all the Matlab variables you have in memory. In the Workspace you can as well show the class (type). In this case you'll see something like (excuse my tiny Workspace window):
Thanks to the class() function. I have C as output from imshowpair() and by typing class(C) I get:
matlab.graphics.primitive.Image
which is the same result as in the Workspace case.
I'm following the regression tutorial at http://www.mathworks.com/help/econ/estimate-regression-model-with-multiplicative-arima-errors.html. In particular, I am browsing the object Fit=fitlm(X,logY). I know I can double-click the object in the Workspace window, but I often don't want more windows. I might just want to list the members at the command line. According to http://www.mathworks.com/help/ident/ug/linear-model-structures.html#bq4gq_u-20, I should be able to do this with the get method. However, Matlab informs me that the Linear Model class doesn't have a get method [tried Fit.get, Fit.get(), and get(Fit)]. What am I missing?
As for browsing the properites using the GUI window, I'm finding that the Residuals property is not present. According to http://www.mathworks.com/help/stats/linearmodel-class.html, it should be present. Thanks for any light that can be shed on my misunderstanding of the class.
I've posted this at:
http://groups.google.com/forum/#!topic/comp.soft-sys.matlab/b0jHdrX6_ZY
You can list all the property names of an object using the properties function. In your case:
properties(Fit)
How can one capture keyboard entry inside a uipanel, i.e. when anything in the panel has focus? I've found that uipanel does not have the KeyPressFcn property. I've read this post from Undocumented Matlab about Java callbacks, but I also can't get KeyPressedCallback to work. For example, if I try to this:
set(h_panel, 'KeyPressFcn', #(src, event)key_press(obj, src, event));
I get this error:
The name 'KeyPressFcn' is not an accessible property for an instance of class 'uicontrol'.
The same thing occurs if I try KeyPressedCallback. I'm afraid I'll have to resort to some sort of hack involving the parent figure, which I would like to avoid if possible.
KeyPressedCallback is a property of the underlying Java object, not the original Matlab uicontrol object. To access the underlying Java control of a Matlab uicontrol, you need to use the findjobj utility, as I believe that I explained in my blog post that you referenced (you probably missed that crucial step):
jPanel = findjobj(hPanel);
jPanel.KeyPressedCallback = #myMatlabCallbackFunc;
Note that Matlab panels only became Java-based objects in HG2 (R2014b, see here). So on R2014a and earlier Matlab releases you will not be able to use this technique, only on one of the newer releases.
I don't see any callback properties that you can use or events to which you can attach a listener.
>> events(h_panel)
Events for class matlab.ui.container.Panel:
ObjectBeingDestroyed
LocationChanged
SizeChanged
ButtonDown
Reset
PropertyAdded
PropertyRemoved
Just the mouse event (ButtonDown) and the ButtonDownFcn callback. Perhaps there are other tricks. Ask Yair Altman!
Ultimately, I have found there are two reasonable solutions to this problem, both involving what I originally described as "some sort of hack involving the parent figure". Both of them require some sort of concept of an "active" panel or object within the figure in question.
Solution 1
Rely on the last-clicked object to direct keyboard input in the figure to that object. Use ButtonDownFcn for every object in the figure that needs keyboard input. In the callback, store the handle of the object in the appdata of the figure as the "active" object. (Something like setappdata(h_fig, 'active_obj', h_obj.) Then set KeyPressFcn in the figure to a function that will get that handle out of the appdata and branch accordingly.
Solution 2
Use some sort of keypress scheme to decide which object to direct further input to. This works well if you have a number of similar objects that merely need disambiguation. For example, set the KeyPressFcn of the figure to a function that uses keys 1-9 to indicate the correspondingly numbered object. Direct further keyboard input to that object or a related function.
Neither method is perfect, and I wish there was a way to avoid going through the figure, but in practice these aren't very complicated to implement. I'm actually using both simultaneously.
If one creates an inputdialog with inputdlg and a default answer, it looks like that:
Which callback command do I need to make it look like that?
The documentation is missing a lot here. It's a kind of "luxury service" for the customer ;)
But I think it would be nice, if it's easy to implement.
This question is actually solved, as I found out that there are convenient functions like uigetfile and uiputfile for my particular case. But the general case of my questions remains unsolved or at least I haven't tested the java approach.
I'm afraid using the builtin inputdlg without changes this is not possible.
At least there's not 'hidden' feature allowing for this.
You'd need access to the underlying java TextField object for that purpose.
You could copy inputdlg to some new place and make your own version of it.
In combination with the findjobj utility the desired functionality in principle exists.
http://www.mathworks.com/matlabcentral/fileexchange/14317-findjobj-find-java-handles-of-matlab-graphic-objects
Things could look like this then:
% create the edit-field:
h = uicontrol('style', 'edit',...);
% get the underlying java object
% this should be a javahandle to a JTextField
jtextfield = findjobj(h);
% set start/end of the selection as desired:
jtextfield.setSelectionStart(startPos);
jtextfield.setSelectionEnd(endPos);