Info
This question is closed. Reopen it to edit or answer.
averaging repeated neighbouring values on logical?
1 view (last 30 days)
Show older comments
My logical array:
ans =
1×79 logical array
Columns 1 through 26
1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0
Columns 27 through 52
0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 53 through 78
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0
Column 79
0
For the values with 1 and 1 (adjacent to each other) are repeated, so I want to average with next/previous closest 0 values.
I currently have the code to average them:
if sum(diff(outliers) == 1) == 1
answ = input('Several consecutive volumes are seen as outliers. Do you want to ''repair'' anyway? [y/n] ','s');
if strcmpi(answ,'y')
for im=1:length(outliers)
bad_slices = r(:,outliers(im))<(M-k*value);
Image(:,:,bad_slices,outliers(im)) = (Image(:,:,bad_slices,outliers(im)-1) + ...
Image(:,:,bad_slices,outliers(im)+1))/2;
end
But it does not work. Thanks in advance!
1 Comment
Sindhu Priya
on 8 Mar 2017
Edited: Sindhu Priya
on 8 Mar 2017
Can you please tell,whether your logical array displayed in the question is the 'outliers' used in the code snippet?
If the 1's are adjacent , can you explain clearly with what values you want to replace?
Answers (1)
Walter Roberson
on 8 Mar 2017
You have a logical array. The only two values that can exist in it are 0 and 1. 1/2 or 2/3 or whatever cannot exist in it, and will be converted to 1 for all non-zero numeric values.
If you need any other numeric values then you will need to convert the array to double
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!