Matlab coder - outputting variable sized cell arrays.
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi,
I am trying to use coder with a function that outputs a variable sized cell array. I've made a toy function that shows my problem (which I would very much like to copy and paste into here but this new editor doesn't let me), so I hope you can see the attached file (Mathworks - please fix asap).
This creates an output cell as follows
a = varCellCompileTest()
a =
1 x 3 cell array
{5 x 1 cell} {2 x 1 cell} {2 x 1 cell}
So 'result' is a 3 x 1 cell array of variable sized cell arrays, and each of those contain variable size doubles. So a cell array of variable sized cell arrays of variable sized double arrays. I can't figure out at all the coder.varsize that will allow me do do that.
Any ideas???
Cheers,
Arwel
2 Commenti
Ryan Livingston
il 18 Gen 2019
Your feedback about the copy and paste issue has been forwarded to the team that owns this editor.
Walter Roberson
il 18 Gen 2019
With the new editor the input fields are not marked as text fields so your browser does not enable Paste in menus. However you can use your shortcut keys such as control V to paste .
Risposte (2)
Andy
il 17 Gen 2019
Hi Arwel,
Codegen has two notions of a "variable sized" matrix. One is stack allocated and has some upper bound (for instance an array of up-to 20 elements), the other can be any size and is heap allocated.
If, for example, you wanted your cell array to be size 1x3 with elements that are cell arrays of size 1x:20 (where :20 means up to 20 elements) of matrices of size 1:20 then you could do the following:
result = {{[1] ; [1]} {[1] ; [1]} {[1] ; [1]}};
coder.varsize('result', [1, 3], [false, false]);
coder.varsize('result{:}', [20, 1]);
coder.varsize('result{:}{:}', [20, 1]);
If you want it to be heap allocated then ideally you would specify the upper bounds to be size "inf", however that doesn't seem to work we're internally investigating this. But in the meantime if you specify an extreme upper bound size coder will treat it as heap allocated. So for example the following:
BIG_VALUE = 655356;
result = {{[1] ; [1]} {[1] ; [1]} {[1] ; [1]}};
coder.varsize('result', [1, 3], [false, false]);
coder.varsize('result{:}', [BIG_VALUE, 1]);
coder.varsize('result{:}{:}', [BIG_VALUE, 1]);
-Andy
1 Commento
Walter Roberson
il 17 Gen 2019
Andy, I notice that you talk about 1x:20 but you code [20,1] ? I also notice that you do not add [true, false] to pin it down to true dimension of 1 instead of the 1 signalling "any number" ?
Arwel
il 21 Gen 2019
1 Commento
Andy
il 21 Gen 2019
Matlab coder does not allow resizing a cell array or matrix through indexed assignment (other than through end+1 in certain circumstances). You either need to reallocate the cell array using the cell() function or do a complete assignment to another cell array.
For your example, the easiest thing would be to change the loop to a complete assignment like this:
result{1} = reflectivity;
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!