deleting numbers in cell array
古いコメントを表示
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
6 件のコメント
Walter Roberson
2020 年 2 月 24 日
There is no built-in function for this purpose.
Please expand on the +/-3 part. Is that referring to row position? Column position?
The every column bit: is that to be determined for each cell entry individually, or is it referring to columns of the 32x5 cell?
sam van Bohemen
2020 年 2 月 24 日
Walter Roberson
2020 年 2 月 24 日
Cell arrays generally contain a different size of array for every entry, and might easily contain different data types.
You posted a numeric array, rather than a cell array.
There is no value that appears in every column of your array. The entries 9, 11, 41, 57, 59, 67 each appear only once in the array and so clearly do not appear in every column.
You did not answer my question about the +/-3. You thought you did, but you failed to add any more information than the original. So I have to ask again whether you are referring to horizontal position, or to vertical position, or to range of values. For example because 9 does not appear in every column, does that mean that entries with value 6, 7, 8, 9, 10, 11, 12 should all be deleted?
When values are deleted, what should replace them? Should the adjacent entries "fall down" to fill the hole?
You mentioned cell array before but I have to wonder whether it would be easier to use a numeric array and nan out what you do not want?
Perhaps you are trying to say that a values should be deleted if it is not the case that every column has some entry that is within the range value-3 to value+3? If you are, then I suspect that you think that after the deletions, that it will be the case that all entries of the resulting array will have the property of being within 3 of some entry from each column. However, that would not generally be the case: some of the values you delete for not having a match in every column, will be anchoring values in some columns, so after the deletion more values become unanchored.
sam van Bohemen
2020 年 2 月 25 日
Robert U
2020 年 2 月 25 日
The description of your problem is ambiguous. It is not clear how your algorithm should work neither the sequential order of commands is clear. I encourage you to describe the desired functionality step-by-step which might help you to write your own code quickly.
From what you wrote (but still not fitting your example values):
- Compare the first element of input matrix within its row with all other values.
- If all other values of said row are not within first element +/- 3, remove first element (by replacing it with NaN)
- Repeat steps 1 & 2 with all other values within input matrix.
- Move all remaining values (not NaN) as much rows up keeping the same column as possible without replacing or reordering numerical values.
Example:
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 = dInput(numRow,numCol) >= dInMin(numRow,:) & dInput(numRow,numCol) <= dInMax(numRow,:);
bRange(numCol) = 0;
if ~any(bRange)
dInput(numRow,numCol) = NaN;
end
end
end
dInput = [10 11 10 NaN 9
39 40 41 40 39
58 NaN 58 57 59
68 NaN 68 69 70]
Does it really make sense to move remaining values up?
Kind regards,
Robert
sam van Bohemen
2020 年 2 月 27 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!