AMcNall
AMcNall

Reputation: 529

One number array, one logic array. If logic == 1 then use number value, if logic ==0 then return no value

I have two matlab arrays, very large, over 41k rows each with 10 columns.

I also have an array of the exact same size filled with 1's and 0's. I need to apply this logic array to the first array and if the value is logic true, pass the number, otherwise if false it must return NaN.

using something like:

output= number(array)

Only gives an output of the positive logic array values but I need to keep the array the same size/structure, how can I do this?

Upvotes: 1

Views: 84

Answers (2)

Jommy
Jommy

Reputation: 1105

First let us generate a dummy matrix and a dummy mask

A = rand(5,3);
M = randi([0 1], 5, 3);

then you can apply the mask to the original matrix

A(not(M)) = nan;

Upvotes: 2

Dan
Dan

Reputation: 45752

Pre-allocate output with NaNs:

output = NaN(size(number))
output(array) = number(array)

Upvotes: 1

Related Questions