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
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.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!