How to delete Table Variables (columns) of a certain value
1 view (last 30 days)
Show older comments
Hello, I have a huge table with lots of data, as well of columns full of 'null' data. The null data are values of '-9999' or '-6999'. I want to remove the columns with null values, so I was thinking of writing a loop to determine if the mean, median, and maximum are all equal to each other, then that column should be deleted. I have attached a subset of my data for an example. My main problem is, is that I don;t know how to start the loop, do you use i's and j's to designate rows and columns??
2 Comments
the cyclist
on 12 Nov 2015
When you say you have a table, do you mean that the data are stored in MATLAB's table object type? If not, how are the data stored in MATLAB?
Accepted Answer
the cyclist
on 13 Nov 2015
Here's one way. I create a small version of your table, then delete the column that has only -6999.
Tau = [0.031985224;
0.003184222;
0.007084112;
0.014945414;
0.021698729];
ru_Tau = -6999*ones(5,1);
tbl = table(Tau,ru_Tau);
tableSize = size(tbl);
removalIndex = false(1,tableSize(2));
for nv = 1:tableSize(2);
removalIndex(nv) = all(tbl{:,nv}==-6999);
end
tbl(:,removalIndex) = [];
You could also remove columns that have any null values, and not all null values. (Just use the any function where I used the all function.)
You should be able to adapt this to getting rid of -9999, or a mix of those two values.
More Answers (0)
See Also
Categories
Find more on Approximate Functions with Lookup Tables 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!