Set specific values in an array to zero

조회 수: 10 (최근 30일)
bbah
bbah 2020년 3월 3일
답변: Srivardhan Gadila 2020년 3월 6일
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.

채택된 답변

Srivardhan Gadila
Srivardhan Gadila 2020년 3월 6일
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;

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by