Collect only non-zero elements of a 3x3xN matrix
3 次查看(过去 30 天)
显示 更早的评论
Hi,
I've a symbolic 3x3xN (with N variable) matrix I with some non-zero elements, like:
I(:,:,1) =
[ 0, 0, 0]
[ 0, 0, 0]
[ 0, 0, Il1]
I(:,:,2) =
[ 0, 0, 0]
[ 0, 0, 0]
[ 0, 0, Il2]
and I want to collect them into an array, but when I try:
[m,v]=find(I~=0)
it returns indices like m=3 v=9. How can I find them from the 3-D matrix and collect them into an array ?
0 个评论
采纳的回答
Image Analyst
2013-1-18
编辑:Image Analyst
2013-1-18
You simply extract them, like this:
nonZeroElements = I(I~=0);
That gives you a big long vector of all the array values that are not zero, in row major order.
更多回答(1 个)
Matt J
2013-1-18
I don't have the Symbolic Math Toolbox, but you could try the NONZEROS command. Don't know if it's overloaded for type sym.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!