How to delete rows/columns of a matrix in Embedded Matlab Fcn?
5 views (last 30 days)
Show older comments
I'm trying to remove specific set of rows and columns of a matrix. In MATLAB, i can just assign them to '[]'. I hope I cannot do that in #codegen ? Please help. Thanks!
0 Comments
Accepted Answer
Mike Hosea
on 9 Jul 2013
I don't know what version you have. MATLAB Coder does currently support deleting rows and columns from a matrix. You will need to start with a variable-size matrix, of course. Use coder.varsize to make any matrix that looks like a fixed-size matrix into a variable-sized one.
You can write something like:
z(rowstodelete,:) = [];
z(:,colstodelete) = [];
where rowstodelete and colstodelete are vectors of row and column indices, respectively. To do both rows and columns at once, I might rather write code like this
ONE = int32(1);
rowsleft = setdiff(ONE:size(z,1),rowstodelete);
colsleft = setdiff(ONE:size(z,2),colstodelete);
z = z(rowsleft,colsleft);
I have to warn you of one thing, however. You will not be able to coax it into making that last assignment an in-place operation. We're working on it. :) -- Mike
2 Comments
Mike Hosea
on 9 Jul 2013
Simulink Coder should work with either, but if your MATLAB Function Block has variable-size outputs you have to jump through some hoops to get Simulink to allow a variable-size signal. You'll probably have to set explicit upper bounds for any variable-size signals coming out of a block, and in 13a you will need to check the variable-size signals box on code-generation/interface/ pane of the model configuration parameters.
More Answers (2)
Guru
on 7 Jul 2013
The Embedded MATLAB Fcn is intended for MATLAB that would resemble C code. How do you suppose you can delete rows/columns from a matrix in C?
That is a rhetorical question, but the answer is quite simply you cannot, nor should you be trying to do so. I have never wrote C for Embedded Systems where I had to delete a row/column from a matrix type of functionality. That is only the case where I didn't know enough about my system to not know how much to allocate for every data that I had.
Short answer: You cannot do so, nor should you be able to as it is not what Embedded MATLAB Fcn is intended for.
0 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!