ilyas patanam
ilyas patanam

Reputation: 5324

How do I efficiently replace elements in the first column of a 3D matrix

I have a 3D matrix: size(data) = [100, 3, 500] I want to replace all the -1s in the first column with 1s. Then, I want to replace all the -1s in the second and third columns with 0s.

Linear indexing doesn't seem to work because I have to replace the second and third column as well.

Upvotes: 0

Views: 128

Answers (1)

Dan
Dan

Reputation: 45752

Can't you just do:

col1 = data(:,1,:);
col1(col1 == -1) = 1;
data(:,1,:) = col1;

etc...?

Upvotes: 2

Related Questions