Trying to isolate rows in a specific time

1 回表示 (過去 30 日間)
Cameron Power
Cameron Power 2018 年 6 月 25 日
コメント済み: Cameron Power 2018 年 6 月 28 日
So I am trying to isolate specific variables in a certain time frame, I have different columns for time and what I need but the data is in a table. Is there a way for me to create a new variable with only the rows of these specific times only. I have attached screenshots of the workshop tables, tahnk you.
  2 件のコメント
Guillaume
Guillaume 2018 年 6 月 25 日
Screenshots are useless. We can't test code on them. Attach demo mat or text files instead.
However, before that you need to explain a lot better what it is you want. An example of desired output would help greatly.
Cameron Power
Cameron Power 2018 年 6 月 25 日
All I want is to take the data file I have with time intervals of 3 or hour sampling for an entire year, and extract only the data within a certain timeframe, say from 1500Hr to 1700Hr. The time in hours is separate from the other information I need so I want to pull out the entire row. I have attached a csv, import it into Matlab to see the format.

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

採用された回答

Ameer Hamza
Ameer Hamza 2018 年 6 月 25 日
First of all, your csv file is not properly formatted. So it is difficult to use csvread() or readtable() directly. The following code use textscan() to read the file and then extract rows based on the specified hour range
f = fopen('Shearwater.Surface.Wind_Direction_and_Wind_Speed.2006.3-hourly.csv');
data = textscan(f, '"%f,%f,%f,%f,%f,%f"', 'HeaderLines', 1);
fclose(f);
data = cell2mat(data);
dates = datetime([data(:,1:4) zeros(size(data,1), 2)]);
dataTable = table(dates, data(:,5), data(:,6), 'VariableNames', {'datetime', 'wind_direction', 'wind_speed'});
Hours = hour(dataTable.datetime);
index = Hours >= 15 & Hours <= 17; % all rows where house is between 15 and 17
requiredTable = dataTable(index, :);
  21 件のコメント
Ameer Hamza
Ameer Hamza 2018 年 6 月 27 日
The screenshot shows that it is reading date time as char array but the above statement should still work. I have no idea what might be causing the issue.
Cameron Power
Cameron Power 2018 年 6 月 28 日
I do not either, thank you for the help thus far and I`ll keep at it

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

その他の回答 (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