working with mwArray in C++: How to extend it...

2 次查看(过去 30 天)
I am working with mwArray's in C++. I have created an empty cellarray as follows:
mwArray r(mxCELL_CLASS);
Now I would like to add a row to this. The Matlab code would be as follows:
>> r = {};
>> r = [ r; { 'asdf', 'fdsa', 1.0, 'foobar' } ]
And I can repeat it to add more rows (ignore performance issues due to not pre-allocating - not material here for what I am doing).
How do I do the above in C++? I tried:
r.Get(1,1).Set( mwArray( "asdf") )
or, equivalently (from what I understand so far):
r(1) = "asdf"
Both produce an error "Attempt to access element at index 1 in array of size 0".
Of course I can pre-allocate - but various google searches suggest that I shouldn't need to in this case, i.e. the mwArray should just grow as needed.
Thanks in advance,

采纳的回答

Kaustubha Govind
Kaustubha Govind 2013-6-4
I'm not sure, but it doesn't seem like mwArray's of double-matrix types can grow dynamically. From the documentation:
Restrictions on Using C++ SETDATA to Dynamically Resize an MWArray
You cannot use the C++ SETDATA function to dynamically resize MWArrays.
For instance, if you are working with the following array:
[1 2 3 4]
you cannot use SETDATA to increase the size of the array to a length of five elements.
I'm assuming this limitation applies to the SET function as well, but you may want to confirm with MathWorks Support.
  1 个评论
matal
matal 2013-6-4
Thank you - I didn't see that part of the documentation. It answers the question directly.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Deploy to C++ Applications Using mwArray API (C++03) 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by