How to take out blank rows from a result table?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Mili Shah
am 31 Jul. 2018
Kommentiert: Peter Perkins
am 3 Aug. 2018
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 Kommentare
Akzeptierte Antwort
jonas
am 31 Jul. 2018
Bearbeitet: jonas
am 31 Jul. 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 Kommentar
Peter Perkins
am 3 Aug. 2018
Or, equivalently, T(T.Var1==0,:)=[]. Substitute the actual variable name in your case.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Tables finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!