フィルターのクリア

Set specific values in an array to zero

9 ビュー (過去 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 Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by