Simulink & Masks: Dynamic access to parameters "evaluate" and "tunable" - matlab

First of all, matlab version is 2011b, so I cannot use Simulink.MaskParameters class.
I have one simulink mask and some parameters inside. I need to determine in my function for each parameter if it is "evaluable" or "tunable".
Those two things are two checkboxes in the mask parameters dialog which you can select for any parameter.
For "tunable", there's the MaskTunableValues property. For "enable", there's the "MaskEnables" property.
Do you know if there's a way to programmatically access the same property but for "evaluate" ?
Thanks

#Phil Goddard's answer shows you how to find the parameter. To complete the answer, the actual parameter is MaskVariables. Evaluate flag is embedded into the MaskVariables string. It is not straightforward to modify this. For example for two parameters MaskVariables string contains something like this:
"a=#1;b=&2;"
In this string the # sign indicates evaluation. Based on that, parameter a is evaluated and parameter b is not. If you want to change the evaluate flag, you need to set this string for MaskVariables parameter exactly how it was except for # or & signs.
For more information see R2011b documentation for mask parameters at https://www.mathworks.com/help/releases/R2011b/toolbox/simulink/slref/f23-18517.html. Towards the bottom of the page there is more detail about MaskVariables parameter.

You're using too old a release for most people to be able to give you an exact solution, however, I'm sure (from memory) that this parameter is available.
If you click on the mask to select the block, then go to the MATLAB command line and type
get_param(gcb,'ObjectParameters')
you'll get a list of all the block properties. (You may already know that since you're aware of MaskTunableValues and MaskEnables.) Near the bottom of that list are all of the properties related to the mask.
Now manually look at each/all of those properties, e.g.
get_param(gcb,'MaskTunableValues')
and you'll find that one of them is a structure that contains the information that you're looking for. (You may need to dig down into the structure to find the specific info.)

Answer for versions > 2011b (tested on 2014b):
Ok found it, actually the matlab documentation is REALLY unclear regarding the Simulink.MaskParameter class and here is how it works:
First, get the Mask class from your block:
mask = Simulink.Mask.get(gcb)
The Mask class is a structure containing all mask parameters:
parameters = mask.Parameters(:)
parameters is a (array of) Simulink.MaskParameter object which will contains all the necessary properties, including Evaluate.

Related

MATLAB member function suggestion

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 .

Simulink - How to create independent custom blocks using callback functions

I am currently coding a new library with several models in it (I am used to Matlab, but not to Simulink). I am able to create a model with block parameters, let's say parameter 'p', and a callback function (initfct) which uses this parameter to compute specific values used inside my model (let say a simple gain K=K(p)).
My problem is that my parameter 'p' and 'K' are available directly on the workspace, what I don't want to. Moreover, if I use twice or more this model in a system, the two models share always the same 'K', which also I don't want to.
So how I can make these variables 'p' and 'K' independent when I use my custom model several time, and to prevent these variables to be viewed in the workspace ?
Should I use "Reference models", but I am not familiar with this feature ... ?
Thanks for you answer,
Michael
Within a callback, gcb returns the path to the block which currently executes the callback. Having the path, you can use get_param to access the parameters.
Just for demonstation purposes, insert the following to the MoveFcn of a delay block:
set_param(gcb,'DelayLength',num2str(randi(10)))
It will randomly change the delay whenever the block is moved.
I am not sure if my answer explains everything you need. It might be that you also need a Mask. If you think this answer is incomplete, please update your question and include a small example model demonstrating your problem.
Thanks, with your help I was able to solve the problem.
To be more specific if someone else has the same problem : you need in your mask to declare also internal variables used by the callback function. Unchecked the relevant options so that they not appear as standard input parameters of your model.
My problem was also to use num2str instead of mat2str (when the gain was a matrix acting on multiple inputs).

What is the return type of the imshowpair command in matlab

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.

Using abbreviations for parameter-value input pairs - why does cellfun's `'UniformOutput', false` work as `'un', 0`?

As a frequent user of cellfun(..., 'UniformOutput', false), I was surprised to discover that the latter two arguments could be input as cellfun(..., 'un', 0). This has immediately shortened my code. My question is, are there any another similar shortcuts/aliases out there?
This doesn't appear to be documented on the MathWorks website. Naughty!
Background
The property part of a Property-value pair can be often be shortened to the beginning of the property string so long as it is still uniquely identifiable (see examples below). They are also often not case sensitive.
As far as I know this is not documented for anything other than figure properties, where it is very briefly documented.
However this behaviour is also implemented in many The MathWorks functions which take property-value pair arguments, and also in some functions which take string arguments with no value pair.
The problems become what other properties are there...
For some functions is not well documented... (and many are either
built-in or obfuscated .p files, so no checking the source).
Most importantly we cannot know if future versions will introduce new
properties.
The use of shortened property names is advised against for this reason, to quote
"using the full property name can prevent problems with futures releases of MATLAB if a shortened name is no longer unique because of the addition of new properties." - Matlab documentation
"Don't shorten your code with P-V abbreviations, it's not worth it, trust me." – Sam Roberts
The brief slightly technical side - This functionality is implemented by default by Matlabs inputParser, however it can be disabled so these abbreviations are by no means guaranteed to work on every function. Only those which use the inputParser in this way or are specifically written to allow this.
Examples using figure properties
Simple Shortening
The following
hFig = figure();
get(Hfig,'Visible')
ans =
on
can be shortened to
hFig = figure();
get(Hfig,'v')
ans =
on
as it is the only property beginning with 'v' (note that 'vi','vis', etc... also work)
Uniqueness
However other properties which start similarly e.g. CurrentAxes, CurrentCharacter & CurrentObject
get(Hfig,'Current')
Error using get
Ambiguous property found.
Object Name: figure
Property Name: 'Current'.
Where as 'currenta','currentc' and 'currento' are uniquely identifiable and would work as intended
Impossible to shorten
A special mention to properties such as Color and ColorMap the name of one is the beginning of another
Color can only be used with its full name, due to any shortening being ambiguous with ColorMap
'ColorMap' can be shorted to 'colorm' however, as before.
Counter examples
This section aims to discourage use of shortened property value pairs by showing some of the seemingly unpredictable and unexpected behaviour.
The semi-undocumented hardcopy has some interesting behaviour the documentation states possible options as -dps,-deps,-dps2,-deps2,-dill,-dhpgl
However '-dh' creates an error where as '-di' works as an abbreviated '-dill' sadly there is no checking the source to see why as it is a .p file
Finally cellfun itself doesn't exactly follow there rules as 'u' should theoretically work if following the rules above, however only 'un' and onwards does.
If a routine uses MATLAB's inputParser functionality then usually any parameter name can be shortened such that it is still unambiguous and is matched case insensitively. The same is true for properties of objects such as get(gcf, 'pos') as a shorter version of get(gcf, 'Position').
However, I don't know if there is any documentation on this usage and I suggest you try it and see.
And 0 is usually equivalent to false (non-zero being true).
PS I would suggest that using these shortcuts is fine at the command line but when writing functions and scripts it is better to use the full names.

Intellij IDEA insert variable names in methods

I'm using Intellij IDEA 13 for android development.
Some methods has long list of parameters. For example, db.query(...) and I can't remember the order of them.
Is there any plugin or can i change some settings to make IDEA insert variables from function template?
Thanks
You have a couple of options. Ctrl+P will show a lit of the parameters, with the current one bolded. As long as you have either the source or javadoc for the library (or JDK/SDK) attached to the corresponding definition, you will see the parameters' names.
If you invoke code completion while entering parameters, IDEA will show at the top only ones that are of the correct type. Furthermore, if one of you local variables is the same name (or similar to) the required parameter's name, it will be at the top of the list. So if there is a method that takes an int named 'width', and I have several int variables, but one is named 'theWidth', it would be at the top. (Again, this assumes you have javadoc or source attached so IDEA can determine parameter names.) If IDEA can find local variables that satisfy all parameters (or all the first x parameters) of the method, there will be an option in the code completion list to complete all of them, The icon will be a double circle. The below screen shot shows how the HttpServletReqest is at the top of the list. So I do not have to remember if the parameter order is "request, response" or "response, "request". Notice the fourth option is to complete both the request and the response.