Grasshopper

algorithmic modeling for Rhino

Hello 

I am fairly new to using C#. I have been using examples to create a GH component that uses Matlab code to evaluation. I manage to do this using items as inputs, but I want to use Lists as input. I am currently stuck when retreiving the data. I use the "GetDataList" command but I get the following error. 

Any help is greatly appreciated 

Views: 570

Replies to This Discussion

the problem is that the second argument to GetDataList has to be a List<T> which MWNumericArray presumably is not. You might need to retrieve a List<double> first (depending on the type of the param you're harvesting from) and then turn it into a MWNumericArray afterwards. Also, with GetDataList you do not need to use the "ref" keyword. So it should look like this:

List<double> i1 = new List<double>();

if(!DA.GetDataList(0, i1)) return;

OK thank you for the help! :) 

So far so good! But turning List<double> into a MWNumericArray is apparently not that easy. I get the following error: Is it possible you know hot to convert a List<double> into MWNumericArray. I have tried different approaches but nothing have worked out yet. 

Here's a reference to the various ways of constructing an MWNumericArray: https://www.mathworks.com/help/dotnetbuilder/MWArrayAPI/html/T_Math...

There's some complexity as MWNumericArray appears to be able to support multi-dimensional arrays. I would maybe start here: https://www.mathworks.com/help/dotnetbuilder/MWArrayAPI/html/M_Math... and supply 1 for the row count and N for the column count where N is the number of items in your list. Then call ToArray() on your List<Double> and pass it as the realData argument. Not knowing anything about matlab or what you're trying to do, this is nothing more than a guess!

Great! I will look into it. Thank you for the help

Just a follow up to others with the same problem. The following code will retrieve the data and convert it into MWNumericArray. After this the matlab component can take a list as input. 

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service