Clear Filters
Clear Filters

Set specific values in an array to zero

9 views (last 30 days)
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.

Accepted Answer

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

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!