How to take out blank rows from a result table?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I currently have a code that calculates specific aspects of 631 csv files, all stored in different folders. Each csv file is titled with a county code, ranging from 1003 to 55139. I only want rows with data (there should be 631) in my result table, but I continuously have 55139 rows - the highest code number I have. I tried to use indexing to find the specific codes, but my result table is still 55139 rows. Code is below.
dataset=xlsread('peaks_locs.xlsx','Sheet2','A1:A632');
whichBin = {2012:2013};
binType = 'annual';
binList = {2012:2013};
geoRegion = 'FIPS';
whichYears = [2012:2013];
whichDay = 'wkday';
%make sure this is the unique ID of the directory you want to use!
randStr = 'gbqo';
for geoCode=dataset(1):dataset(631)
csvData = ['tweetogramsMili/tweetograms_' binType '_' geoRegion '_2012_2013_' randStr '/' binType '/' whichDay '/' num2str(geoCode) '.csv'];
if ~exist(csvData,'file'),continue,end
tweetogramData = csvread(csvData);
tweetogramSmooth = smooth(tweetogramData);
[lunchpk, loc1] = max(tweetogramSmooth(44:60));
[dinnerpk, loc2] = max(tweetogramSmooth(68:92));
lunchloc = loc1 + 43;
dinnerloc = loc2 + 67;
outTable(geoCode,:) = table(geoCode, whichDay, lunchloc, lunchpk, dinnerloc, dinnerpk);
end
Essentially, how can I change my code so the "outTable" result gives me just a 631 row table, rather than one that is 55139 rows? All the rows that do not have data currently have a '0' in them.
0 commentaires
Réponse acceptée
jonas
le 31 Juil 2018
Modifié(e) : jonas
le 31 Juil 2018
Let's say you have a table
T=table([1;0;2;3],[3;0;1;5])
T =
4×2 table
Var1 Var2
____ ____
1 3
0 0
2 1
3 5
And we want to remove rows with zeros.
T(T{:,1}==0,:)=[]
T =
3×2 table
Var1 Var2
____ ____
1 3
2 1
3 5
1 commentaire
Peter Perkins
le 3 Août 2018
Or, equivalently, T(T.Var1==0,:)=[]. Substitute the actual variable name in your case.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Other Formats dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!