How to set values to NaN when they AREN'T within the given indices

13 views (last 30 days)
I am attempting to set several values in a large matrix to NaN based on indices that I do not want to have NaN values. I attempted using logicals but matlab doesn't change anything (see photo). In this example, I expect every value but the bottom right to be set equal to NaN. I checked previous posts and this was how it was done in 2014.

Answers (1)

Jonas on 17 Jul 2021
a(~(X==3 & Y==3))=NaN;
which equals
a(X~=3 | Y~=3)=NaN;

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by