populating a value array w/matlab function

Discussions about integrations with other 3th party tools

Moderator: Moderators

populating a value array w/matlab function

Postby rmartinez@draper.com » Thu Feb 01, 2018 10:55 am

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
rmartinez@draper.com
Forum Newbie
Forum Newbie
 
Posts: 12
Posts Rating:1
Joined: Tue Oct 27, 2015 8:59 am

Re: populating a value array w/matlab function

Postby jirawat.l@nomagic.com » Thu Feb 01, 2018 10:56 pm

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
You do not have the required permissions to view the files attached to this post.
jirawat.l@nomagic.com
Customer Support
Customer Support
 
Posts: 45
Posts Rating:3
Joined: Mon Nov 16, 2015 1:57 am

Re: populating a value array w/matlab function

Postby rmartinez@draper.com » Fri Feb 02, 2018 9:40 am

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
You do not have the required permissions to view the files attached to this post.
rmartinez@draper.com
Forum Newbie
Forum Newbie
 
Posts: 12
Posts Rating:1
Joined: Tue Oct 27, 2015 8:59 am

Re: populating a value array w/matlab function

Postby jirawat.l@nomagic.com » Mon Feb 05, 2018 10:23 pm

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
You do not have the required permissions to view the files attached to this post.
jirawat.l@nomagic.com
Customer Support
Customer Support
 
Posts: 45
Posts Rating:3
Joined: Mon Nov 16, 2015 1:57 am

Re: populating a value array w/matlab function

Postby rmartinez@draper.com » Tue Feb 06, 2018 11:11 am

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
rmartinez@draper.com
Forum Newbie
Forum Newbie
 
Posts: 12
Posts Rating:1
Joined: Tue Oct 27, 2015 8:59 am


Return to Integrations

Who is online

Users browsing this forum: No registered users and 0 guests

cron