replace all values of cells between two positions
Show older comments
I have a matrix and vectors of noise onsets and correspondig offsets positions for each row in the matrix.
I need to replace all the cell values between onsets and offsets with NaN's. For example:
matrix =
29.6676 48.8609 67.9136 33.5357 89.0923 61.7666 97.8681 81.8149 43.2392 52.6876
31.8778 57.8525 39.5515 67.9728 33.4163 85.9442 71.2694 81.7547 82.5314 41.6799
42.4167 23.7284 36.7437 13.6553 69.8746 80.5489 50.0472 72.2440 8.3470 65.6860
50.7858 45.8849 98.7982 72.1227 19.7810 57.6722 47.1088 14.9865 13.3171 62.7973
onsets_row1 = [1 5]
offsets_row1 = [3 8]
new_matrix =
NaN NaN NaN 33.5357 NaN NaN NaN NaN 43.2392 52.6876
31.8778 57.8525 39.5515 67.9728 33.4163 85.9442 71.2694 81.7547 82.5314 41.6799
42.4167 23.7284 36.7437 13.6553 69.8746 80.5489 50.0472 72.2440 8.3470 65.6860
50.7858 45.8849 98.7982 72.1227 19.7810 57.6722 47.1088 14.9865 13.3171 62.7973
How do I replace all the values between onsets and offsets?
thnx
3 Comments
KALYAN ACHARJYA
on 16 Nov 2018
Can you elaborate again, with small example?
KSSV
on 16 Nov 2018
onsets_row1 = [1 5]
offsets_row1 = [3 8]
what are those?
yarden d
on 16 Nov 2018
Accepted Answer
More Answers (2)
Bruno Luong
on 16 Nov 2018
new_matrix = matrix;
for k=1:length(onsets_row1)
new_matrix(onsets_row1(k):offsets_row1(k)) = NaN;
end
1 Comment
madhan ravi
on 16 Nov 2018
+1 epic
Bruno Luong
on 16 Nov 2018
Second solution, use this File Exchange MCOLON
new_matrix = matrix;
new_matrix(mcolon(onsets_row1,offsets_row1)) = NaN;
Categories
Find more on Interpolation of 2-D Selections in 3-D Grids in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!