0
votes

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.

1
When you say "all three columns", does that mean "everything"? Because (in matlab terminology) your matrix has 100 rows, 3 columns and 500 pages. If this is true, a simple data(data == -1) = 0; will suffice.DasKrümelmonster
Sorry, there was a typo. I edited it. I want to replace the -1 in the first column by 1 and the -1s in the remaining columns by 0.ilyas patanam

1 Answers

2
votes

Can't you just do:

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

etc...?