working with mwArray in C++: How to extend it...
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Deploy to C++ Applications Using mwArray API (C++03) en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!