Remove columns from cell array when several cells in such columns have zero-values
Show older comments
Hi all,
I use R2019b. I have a cell array (11 x 400) in which the first row and first column contain words (e.g. 'Person#001', 'Person#002', ... 'Person#399' for the first row and 'ITEM1', 'ITEM2', ... 'ITEM10' for the first column). The remainder of the cells (2:end,2:end) are occupied by numerical values that range from 0 to 1. This dataset represents the amounts of each of the 10 items belonging to each of the 399 persons.
Some of these persons have only 0 values for all of their respective numerical values. I am trying to remove the columns from the cell array that contain only zero numerical values in rows 2 through 11 (i.e. for all 10 items). In the example below (that represents a condensed version of my data), I want the columns with 'Person#004' and 'Person#006' at the top to be removed entirely. There are several of these all-zero columns throughout the entire dataset and ideally this script would remove all of them.
Thanks in advance for your help!
BEFORE
'Person#001' 'Person#002' 'Person#003' 'Person#004' 'Person#005' 'Person#006' . . . 'Person#399'
'ITEM1' 0 0.2 0.4 0 0.1 0 0.4
'ITEM2' 0 0 0.2 0 0 0 0.1
'ITEM3' 0.5 0 0.1 0 0 0 0
'ITEM4' 0 0.1 0 0 0 0 0.3
AFTER
'Person#001' 'Person#002' 'Person#003' 'Person#005' . . . 'Person#399'
'ITEM1' 0 0.2 0.4 0.1 0.4
'ITEM2' 0 0 0.2 0 0.1
'ITEM3' 0.5 0 0.1 0 0
'ITEM4' 0 0.1 0 0 0.3
Accepted Answer
More Answers (0)
Categories
Find more on Performance and Memory 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!