フィルターのクリア

How to take out blank rows from a result table?

1 回表示 (過去 30 日間)
Mili Shah
Mili Shah 2018 年 7 月 31 日
コメント済み: Peter Perkins 2018 年 8 月 3 日
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.

採用された回答

jonas
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
Peter Perkins 2018 年 8 月 3 日
Or, equivalently, T(T.Var1==0,:)=[]. Substitute the actual variable name in your case.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by