Effacer les filtres
Effacer les filtres

Set specific values in an array to zero

9 vues (au cours des 30 derniers jours)
bbah
bbah le 3 Mar 2020
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.

Réponse acceptée

Srivardhan Gadila
Srivardhan Gadila le 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;

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by