Azzera filtri
Azzera filtri

Set specific values in an array to zero

9 visualizzazioni (ultimi 30 giorni)
I have an array containing displacements of nodes UY (Nx1) and a matrix containing the nodes of specific elements elems (Nx8). Now i want to keep all the displacements of the nodes of the specific elements and set the other ones to zero. I tried like this:
UY ;
elems;
member = ismember(UY,UY(elems(:,:)));
indices = find(member);
UY(~indices,1) = 0;
It is somehow not working. I hope somebody can help me.

Risposta accettata

Srivardhan Gadila
Srivardhan Gadila il 6 Mar 2020
Based on the above information and code I'm assuming that the values of the matrix elems are indices of nodes UY (1<=elems(i,j)<=N).
Then make use of the functions unique & setdiff as follows:
nodesOfSpecificElements = unique(elems);
UY(setdiff(1:N,nodesOfSpecificElements)) = 0;

Più risposte (0)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by