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

2 visualizzazioni (ultimi 30 giorni)
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,

Risposta accettata

Kaustubha Govind
Kaustubha Govind il 4 Giu 2013
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 Commento
matal
matal il 4 Giu 2013
Thank you - I didn't see that part of the documentation. It answers the question directly.

Accedi per commentare.

Più risposte (0)

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by