4 views (last 30 days)

I have a 32x5 cell array.

I want to delete all numbers (+/- 3 either side of each number) that do not appear in every column.

Is there a function that can help me?

Thanks

Sam

Robert U
on 2 Mar 2020

Hi sam van Bohemen,

Thank you for your description. I guess the following code will do the trick:

dInput = [10 11 10 28 9; ...

39 40 41 40 39; ...

58 47 58 57 59; ...

68 58 68 69 70];

dInMin = dInput - 3;

dInMax = dInput + 3;

for numRow = 1:size(dInput,1)

for numCol = 1:size(dInput,2)

bRange = all(any(dInput(numRow,numCol) >= dInMin(:,[1:numCol-1,numCol+1:end]) & dInput(numRow,numCol) <= dInMax(:,[1:numCol-1,numCol+1:end]),1));

if ~bRange

dInput(numRow,numCol) = NaN;

end

end

end

bRowMoved = true;

while bRowMoved

for numRow = 2:size(dInput,1)

bRowMoved = false;

for numCol = 1:size(dInput,2)

if isnan(dInput(numRow-1,numCol))

dInput(numRow-1,numCol) = dInput(numRow,numCol);

dInput(numRow,numCol) = NaN;

bRowMoved = true;

end

end

end

dInput(all(isnan(dInput),2),:) = [];

end

Kind regards,

Robert

Opportunities for recent engineering grads.

Apply Today
## 6 Comments

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/507172-deleting-numbers-in-cell-array#comment_801352

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/507172-deleting-numbers-in-cell-array#comment_801352

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/507172-deleting-numbers-in-cell-array#comment_801356

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/507172-deleting-numbers-in-cell-array#comment_801356

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/507172-deleting-numbers-in-cell-array#comment_801377

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/507172-deleting-numbers-in-cell-array#comment_801377

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/507172-deleting-numbers-in-cell-array#comment_801791

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/507172-deleting-numbers-in-cell-array#comment_801791

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/507172-deleting-numbers-in-cell-array#comment_801880

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/507172-deleting-numbers-in-cell-array#comment_801880

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/507172-deleting-numbers-in-cell-array#comment_802853

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/507172-deleting-numbers-in-cell-array#comment_802853

Sign in to comment.