e HVL (IEEE 1647): How to set 'X' value? - specman

I would like to initialize some variables in my verification environment to 'X' value. How can I set 'X' value in e?
Thank you for your help

You can set values other than 0 and 1 using the MVL (multi-valued logic) functions. For a one-bit wide signal this would be:
sig.put_mvl(MVL_X);
It's also possible to assign multi-bit signals by writing:
wide_sig.put_mvl_list({ MVL_X, MVL_X, ... });
These methods only apply to ports. If you want to assign variables to X you need to declare them as being of type mvl or list of mvl.

Related

Numerical values associated with Drop Down options

So I am creating an app to work out a value based on a series of variables. The variables are:
Gender
Age
Weight
Creatinine
Here's what the app looks like:
In order to simplify the process somewhat I decided to make the gender selection a dropdown menu, this has caused me some issues since I have it setup like so:
And the maths associated with the button looks like so:
function CalculateButtonPushed(app, event)
gender = app.PatientGenderDropDown.Value ;
age = app.PatientAgeEditField.Value ;
weight = app.LeanBodyWeightEditField.Value ;
serum = app.SerumCreatinineEditField.Value ;
final = (gender*(age)*weight) / (serum) ;
app.ResultEditField.Value = final ;
end
end
Running this gives the following error:
Error using
matlab.ui.control.internal.model.AbstractNumericComponent/set.Value
(line 104) 'Value' must be numeric, such as 10.
As far as I am aware, the values I input into ItemsData are numeric values. Have I missed something or is there a better way to do this?
If you put a breakpoint in the offending file on the appropriate line (by running the below code),
dbstop in uicomponents\+matlab\+ui\+control\+internal\+model\AbstractNumericComponent.m at 87
you could see the following in your workspace, after clicking the button:
There are two separate problems here, both of which can be identified by looking at the newValue validation code (appearing in AbstractNumericComponent.m):
% newValue should be a numeric value.
% NaN, Inf, empty are not accepted
validateattributes(...
newValue, ...
{'numeric'}, ...
{'scalar', 'real', 'nonempty'} ...
);
Here are the issues:
The new value is a vector of NaN.
The reason for this is in this line:
final = (gender*(age)*weight) / (serum) ;
where serum has a value of 0 - so this is the first thing you should take care of.
The new value is a vector of NaN.
This is a separate problem, since the set.Value function (which is implicitly called when you assign something into the Value field), is expecting a scalar. This happens because gender is a 1x4 char array - so it's treated as 4 separate numbers (i.e. the assumption about ItemsData being a numeric is incorrect). The simplest solution in this case would be to str2double it before use. Alternatively, store the data in another location
(such as a private attribute of the figure), making sure it's numeric.

Matlab: specifying argument's name when passing it to function (Ruby `hash`)

Is it possible to define and use a function like this?
generate_mode_matrix_and_mode_frequency_and_Hw(generate_Hw: true);
function generate_mode_matrix_and_mode_frequency_and_Hw(generate_Hw)
if generate_Hw ## NOTICE: this argument is optional
.....
end
end
What I want is to specify the name of the argument when passing it. In ruby it's called hash.
The point of doing this is that, when using it, the coder know what the true mean without comment. This is
Compare this 2:
generate_mode_matrix_and_mode_frequency_and_Hw(generate_Hw: true)
generate_mode_matrix_and_mode_frequency_and_Hw(true)
Clearly, the first one is more clear.
Notice: generate_Hw is an optional argument. So without specifying it, the function would also work.
You can use something similar to Property\Value pairs:
function Foo(varargin)
for n=1:2:nargin
switch varargin{n}
case 'var1'
var1 = varargin{n+1};
case 'var2'
var2 = varargin{n+1};
end
end
In this example if you use Foo('var1',value) then var1 would get the desired value. If you don't specify the pair 'var1',value in the input, then var1 will not exist in Foo.

Giving default values to only some function variables in Matlab

I made a Matlab function
function foo(argone, argtwo)
The begining of the function allow to have default choices for those variables if the function is called only with one or even zero arguments
function foo(argone, argtwo)
if(~exist('argone','var'))
argone = defaultargone;
end
if(~exist('argtwo', 'var'))
argtwo = defaultargtwo;
end
... % Rest of the code
We can call the function as
foo() % Default values are assigned to argone and argtwo
foo(myargone) % Default value given to argtwo
foo(myargone, myargtwo) % No default values are used
But how to be able to give default value to argone only?
If function is called with
foo(~, myargtwo)
no default values are used; argone get the null value (that is not the default value)
Thank you for your help
An alternate way would be to include the option for handling an empty input:
function foo(argone, argtwo)
if ~exist('argone','var')||isempty(argone)
argone = defaultargone;
end
if ~exist('argtwo','var')||isempty(argtwo)
argtwo = defaultargtwo;
end
Then any of these should work:
foo()
foo([],[])
foo(argone)
foo([], argtwo)
The language itself does not support such inputs. A common workaround uses parameter value pairs.
Usange would be
foo('myargone',1, 'myargtwo',2)
foo('myargtwo',3)
foo('myargone',4)
In your function, you have to use varargin and the input parser

Matlab set param from array

In Matlab, in order to change the value of a block I do
set_param('model/V','Amplitude','100')
and the value of V is 100. But if I do
for i=1:10
set_param('model/V','Amplitude','P(i)')
...
end
The it stores the value of V as P(i). But in order to access the i-th element of the 20-by-1 P matrix, I need to refer to it by P(i). What is my error?
Change the value to string using:-
set_param('model/V','Amplitude',num2str(P(i)) );
Also it will set the value of 'model/V' to P(20) i.e. last one.
You might want to loop through the current blocks too
Something like : (just example)
set_param(['model/V' num2str(i)],'Amplitude',num2str(P(i)) );
for model/V1, model/V2,...model/V20 .

What is the neatest way of passing flags to a Matlab function?

I'm designing a function that takes as argument one structure and any number of flags. The function will contain a couple of ifs checking whether a specific flag is set.
What is the neatest way to achieve this? I was thinking about passing the flags as separate string arguments. Is there a neater solution?
I would do it like using varargin and ismember:
function foo(arg1,arg2,varargin)
flag1=ismember('flag1',varargin);
flag2=ismember('flag2',varargin);
flag3=ismember('flag3',varargin);
And you can call the function like that:
foo(a1,a2,'flag3','flag1')
This will activate flag1 and flag3.
Pass in a struct of flags:
options = struct(...
'Flag1', true, ...
'Flag2', true, ...
'MySpecifFlag', false ...
);
Foo(st, options);
To get a list of all the flags that were explicitly set by the user, use fieldnames:
passedOptions = fieldnames(options);
This returns a cell array whose elements are strings - these strings are the flags set by the user; the ith element of the array is the ith flag set by the user.
Access the value of each flag that was set:
options.(passedOptions{i}) %# gets the value of the flag corresponding to passedOptions{i}
Probably you can pass varargin -
The even will be names of the flags and the odd their values (except the first)
function Foo(st, varargin)
end
Then pass values like this:
Foo(st, 'Flag1', true, 'Flag2', false)
Foo(st, 'Flag3', true, 'MyFlag2', false,'MySpecialFlag',false)
Foo(st)
To access the variable arguments use
varargin{2}, varargin{3},
etc..
To check whether a specific flag was passed, do
flagNames = varargin{2:end};
ismember('MyFlag',flagNames )
You can pass the flags as a string with 0s and 1s. The order can be fixed or you can also pass a cell array of flag names.
flagstr = '101'; %# string passed as argument
flaglog = flagstr=='1'; %# logical vector, can be accessed as flaglog(i)
fname = {'flag1','flag2','flag3'}; %# flag names, can be passed as argument or defined in the function
fvalue = num2cell(flaglog); %# create cell array
flags = cell2struct(fvalue, fname, 2); %# create a structure, so you can access a flag with flags.flag1
You need to take care to match the length of fvalue and fnames. if they are different you can either generate an error or somehow correct it (remove the extra flags or fill the absent by default value).
varargin is the way to go for parsing a variable number of arbitrary input arguments. If you want somemore control over the calling syntax of the function (i.e. optional/required arguments) then I suggest looking into Matlab's input parser.