Remove elements from array based on logical condition
古いコメントを表示
I am trying to write a for loop/if statement that goes through two arrays and compares the elements of each array to each other. If both values at the specified index equal 0, then I want to remove those two elements.
When I try and run my code, it seems to freeze. Any suggestions on how I can go about fixing this?
% x = array with size 1x875175
% y = array with size 1x875175
% Goal: when element at x AND y = 0, then delete. I do not want an ordered pair of (0,0).
for k = 1:length(x)
if x(1,k) == 0 & y(1,k) == 0
x(:,k) = [];
y(:,k) = [];
end
end
If I try to script the if statement with x(1,k) and y(1,k) then I get an error: A null assignment can have only one non-colon index.
Alternative Option: Instead of finding where the indexed elements are equal to 0, what about finding where both elements are > 0 and saving those elements?
Thanks!
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!