How to take out blank rows from a result table?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
jonas
2018년 7월 31일
편집: jonas
2018년 7월 31일
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
Peter Perkins
2018년 8월 3일
Or, equivalently, T(T.Var1==0,:)=[]. Substitute the actual variable name in your case.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!