Page 1 of 1

populating a value array w/matlab function

PostPosted: Thu Feb 01, 2018 10:55 am
by rmartinez@draper.com
Hi,

I've written a very simple m-file that takes as input an array (can be arbitrary length) multiplies by a number, (say 3) and then outputs the result.

I put this script in a parametric diagram and the inputs and outputs are shown correctly. I also set up value properties (with multiplicities 1...*) on the input and output.

However, when I try to pass a simple array [1, 2, 3] I get "Incorrect number format!"

If i used the matlab prompt in the simulation engine and pass the array ...the input is recorded properly but the output is always the last value.

Any ideas on how to overcome ?

Thanks

-Bob Martinez

Re: populating a value array w/matlab function

PostPosted: Thu Feb 01, 2018 10:56 pm
by jirawat.l@nomagic.com
Dear Customer,

when I try to pass a simple array [1, 2, 3] I get "Incorrect number format!"

Could you please tell us that how you pass the array to the input value (by default value, by instance or etc)?

the input is recorded properly but the output is always the last value.

Please ensure that the multiplicity of constraint parameters is 1...* or not.
constraintMultiplicity.png


if the multiplicity is correct but you still get only the last value, please send us the model for investigation.

Best regards,
No Magic Customer Support

Re: populating a value array w/matlab function

PostPosted: Fri Feb 02, 2018 9:40 am
by rmartinez@draper.com
Here is the picture




where "input" is an array of numbers that gets sent to a Matalb function

I guess I have two questions:

1) How do you create an array of values ? v = [1 3 5....etc] where v is a value property.

2) How do you create a block that contains this array ?

-Bob

Re: populating a value array w/matlab function

PostPosted: Mon Feb 05, 2018 10:23 pm
by jirawat.l@nomagic.com
Dear Customer,

You can use the instance of <<block>> for creating the array and use the instance as the target of the simulation. You can assign the multiple values to instance.
I attached sample and script file. Please check the attached model.
array.zip


In your picture. You have to set the multiplicity of constraint parameters "indata" and "outvec" to [1..*] for support the array value.

Best regards,
No Magic Customer Support

Re: populating a value array w/matlab function

PostPosted: Tue Feb 06, 2018 11:11 am
by rmartinez@draper.com
Hi

Thanks !....this was detailed enough to solve my problem. I was hung-up on

1) multiplicity of the constraint parameters
2) not creating instance slot values.

Interestingly, using the Matlab engine (and working from the console prompt) i could create a vector of values e.g. input=[1 2 3] and then call the script (w/matlab prompt)
output = generatevec(input) and it would automatically create the vectors....something I could not do working in MD alone.

Thanks again !

-Bob