Effacer les filtres
Effacer les filtres

Collect only non-zero elements of a 3x3xN matrix

2 vues (au cours des 30 derniers jours)
Marco
Marco le 18 Jan 2013
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 ?

Réponse acceptée

Image Analyst
Image Analyst le 18 Jan 2013
Modifié(e) : Image Analyst le 18 Jan 2013
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 commentaire
Walter Roberson
Walter Roberson le 18 Jan 2013
Column major order rather than row.

Connectez-vous pour commenter.

Plus de réponses (1)

Matt J
Matt J le 18 Jan 2013
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 commentaire
Marco
Marco le 18 Jan 2013
I tried it but it returns:
Undefined function 'nonzeros' for input arguments of type 'sym'.

Connectez-vous pour commenter.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by