How to dynamically add edit boxes in MATLAB GUI? - matlab

I use the inputdlg function to display a dialog box in which the user writes in several edit boxes. The number of boxes depends on the value of a variable, so I can have 3 ou 11 boxes but I figured out how to update the number of boxes in the dialog box according to the value of this variable.
Now I want to do the same thing with a GUI (and not a simple dialog box) because I would like to add some features in it (like a static text) by using uicontrol. (I'm forced to do that because it's impossible to extract the handle of the dialog box displayed by inputdlg). When you do it with GUIDE, you have to specify how many boxes you have but I can't give a fixed number of boxes, it's variable.
To sum up, I would like to dynamically increase the number of edit boxes in a GUI. How can I do that?

Suppose you want to use uicontrol.
The help is very comprehensive.

Your best bet is to have a generic function that you can call with the necessary parameters to define the object you wish to create.
Something along the lines of this:
function CreateEditBox ( various parameters/necessary handles )
set( objectHandle, 'Property', value )
% and more for whatever it is you need to define.
end

Related

How can I use dialog box in the mask editor to make my constant change?

I have a simple block.
I create a mask using this block.
Then I edit the mask using popup. Now i have 2 choices. Sin or Cos.
This is where it gets complicated. I want my block which I called as 'Result' in the constant block is equal to 1 if i chose sin and , 0 if I chose answer as cos. I tried to write a callback function but I couldnt do it.
I am kinda new to these staff. Hope you can help me.
Thanks.
There are at least 3 problems:
You do not want your variable to be evaluated, so you need to de-select that option in the Mask Editor.
You do not want to call your variable Result. At present your mask has Result being a string (either sin or cos), but the model expects Result to be a numeric value. Let's assume you change the mask to create a variable called fcn_selected instead.
You have not shown us your callback code, nor told us where you put the code.
For 3. you want to write code something like
switch fcn_selected
case 'Sin'
Result = 1;
case 'Cos'
Result = 0;
end
And you want to put the code on the Mask Editor's Initialization pane.

How to change Font Size in Simulink Scope?

I'm trying to change font size of axes, legend and title of a scope used in simulink. I've seen lots of answers for changing font size in a plot made from workspace, like using 'setgca' and 'fontsize' property, but couldn't find anything about changing font size within a simulink scope.
I have tried couple methods, but there's no direct way to implement this. However, we could adjust the font size of titles and x/y labels inside the Figure associated with scope
Directing to scope to figure
After you run the scope, click the scope. In the task bar, select
File > Print to Figure
This will bring you to a figure where we can edit figure's fonts.
Edit font inside the figure
Edit > Figure Properties
In the pop-up window, edit the font.
In simulink is possible to change the font style and size using going to:
Diagram > Format > Font Styles for Model
There you can change the font style and size for blocks, lines and annotations.
There isn't any functionality to change these from a pulldown menu, however, they can all be changed using code.
The primary thing to note is that a Simulink Scope is just a MATLAB Figure Window in disguise, and hence it can be manipulated using standard Handle Graphics commands once you have the handle to the scope block you want to manipulate.
For instance to change the size of the legend you'd do:
% Get the Name of the block you want to change
scope_name = get_param(gcb,'Name');
% Get the handle of the figure window used for the scope
hs = findall(0,'Tag','SIMULINK_SIMSCOPE_FIGURE','Name',scope_name);
% Get the handle to the axes on the scope
% (For simplicity, here we'll assume there is only one axis on the scope.
% If there are multiple axes, then you'll need to select which one to manipulate.)
ha = findall(hs,'Type','Axes');
% Get the handle to the legend
hl = get(ha,'Legend');
% Change the font size
set(hl,'FontSize',12);
Given any of the above handles you can manipulate it using set and get just like any Handle Graphics object.
I am not sure how to access the scope object from MATLAB, however, I managed to change the legend and titles text sizes by simply resizing the scope window. I know it's not exactly the right way to do this but it works.

Get selected UIControl in a GUI

How is it possible to find out which control in a given MATLAB GUI is currently selected by the user?
For example I want to find out which edit box in the GUI is currently focused since I want to exploit the figures WindowScrollWheelFcn to allow increasing/decreasing numeric values by scrolling up/down while the relevant input is selected.
Let f be a handle to the GUI figure. Then
h = get(f, 'CurrentObject')
returns a handle h to that figure's current object, which is the one most recently selected in that figure (see the documentation of figure properties for more information).
(Note that gco returns the current object in the current figure. This is not what you want, because the user may have clicked an object in another figure).

Change label of data tips on bode nichols diagram

When we plot a bode/nichols locus, the name of workspace variable is used
tmp=ss(1,1,1,0);
nichols(tmp);
will use 'tmp' as label.
When using more complex data, matlab is using 'untitled1','untitled2',...
tmp={ss(1,1,1,0) , ss(1.2,1,1,0)};
nichols(tmp{:});
How can I change this label programmatically?
Ideally, I'd like a solution working with Matlab 6.5.1, but I'm also interested in solutions restricted to newer versions.
You can modify the labels programmatically via their graphics handles. It looks like the values you want to change are the DisplayName property of some of the children of the current axis. So in your first example, I can change the display name like this:
ch = get(gca,'Children');
set(ch(1),'DisplayName','Fred');
In general, I'm not sure how to predict which children of the current axis are the ones you need to change. For the second example you give, the two curves appear to be the second and third children when I run your code.

Star rating in Matlab GUI

Is there a way to add a rating button to a matlab GUI?
something like that
http://www.fyneworks.com/jquery/star-rating/
AFAIK there isn't a built in UIControl that provides this functionality. The closest control that I can think of is slider. Specify the MIN, MAX, and step size and the user will be bound to forced to select one of a few specific values.
Other options integrating a JAVA component into your GUI
http://blog.noblemaster.com/2010/08/31/star-rating-panel-for-java-swing/
http://code.google.com/p/starrating/
Or you can come up with a clever way to do it in matlab using a collection of radiobuttons and images.
I ended up writing my own rating system
http://www.mathworks.com/matlabcentral/fileexchange/41997-star-rating