필터 지우기
필터 지우기

Collect only non-zero elements of a 3x3xN matrix

조회 수: 2 (최근 30일)
Marco
Marco 2013년 1월 18일
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 ?

채택된 답변

Image Analyst
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
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.
  댓글 수: 1
Marco
Marco 2013년 1월 18일
I tried it but it returns:
Undefined function 'nonzeros' for input arguments of type 'sym'.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by