Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
matal
matal el 3 de Jun. de 2013
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,

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Deploy to C++ Applications Using mwArray API (C++03) en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by