How to Initailize MWStructArray

 Akzeptierte Antwort

Friedrich
Friedrich am 12 Jul. 2011

1 Stimme

Hi,
#include "mclcppclass.h"
const char* fields[] = {"a", "b"};
mwArray my_struct(1, 5, 2, fields);
See doc for more:

4 Kommentare

Sadanand
Sadanand am 12 Jul. 2011
Thnx. I am calling matlab function from my C# code. Matlab function always accepts MWArray type. I want to send MWStructArray to the method. How do I do that?
Friedrich
Friedrich am 12 Jul. 2011
Is this about MATLAB Builder NE? Or do you call ML as COM Server from C#? If its Builder NE than: MWARRAY is an abstract class, so creating an MWSTRUCTARRAY and passing it to the ML function will work fine:
MWArray[] result= null;
MWStructArray my_struct= null;
MWStructArray ret_struct= null;
String[] myFieldNames= { "a", "b" };
my_struct= new MWStructArray(1, 5, myFieldNames);
my_struct["a", 1]= new MWCharArray("some text here");
my_struct["b", 1]= 1337
result = your_builder_class_call.function(1,my_struct)
//when you know you get an struct array back do:
ret_struct = (MWStructArray)result[0];
Friedrich
Friedrich am 12 Jul. 2011
Maybe look at the phonebook example provided in the doc:
http://www.mathworks.com/help/releases/R2011a/toolbox/dotnetbuilder/ug/brl3b0g-1.html
(click on the PhoneBookApp.cs)
Sadanand
Sadanand am 12 Jul. 2011
Thanx Friedrich.. I was unable to do as I was using MathWorks.MATLAB.NET.NAtive.Arrays. Now i m using MathWorks.MATLAB.NET.Arrays so its working fine.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by