How to delete rows/columns of a matrix in Embedded Matlab Fcn?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Mike Hosea
2013-7-9
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 个评论
Mike Hosea
2013-7-9
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.
更多回答(2 个)
Guru
2013-7-7
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulink Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!