Extract data by more indexes
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi Everyone,
I made a code that extracts the data between two years and every six hours. My data starts from 1979 and arrives 2019 and for each day I have 23 values, with the code below I would obtain a sheet data that starts from 1985 and arrives 2005 and for each days have 4 values (1 value every six hours). The question is, the index that I wrote is right to do the operation above?
format long g;
folderData = 'D:\Valerio\data\ERA_5';
filePattern = fullfile(folderData, '*.xlsx');
xlsFiles = dir(filePattern);
nFiles = length(xlsFiles);
for ii = 1:nFiles
filename = fullfile(xlsFiles(ii).folder, xlsFiles(ii).name);
files{ii} = xlsread(filename);
end
DIR = files(1);
Hs = files(2);
time = files(3);
Tp = files(4);
U_wind = files(5);
V_wind = files(6);
YYMMDD = cell2mat(time);
Years = YYMMDD(:,1);
Month = YYMMDD(:,2);
Days = YYMMDD(:,3);
HH = YYMMDD(:,4);
H_s = Hs{:,1};
T_p = Tp{:,1};
dir = DIR{:,1};
uwind = U_wind{:,1};
vwind = V_wind{:,1};
index = find(((HH == 0)|(HH == 6)|(HH == 12)|(HH == 18))&(Years >= 1985 & Years <= 2005));
YY = Years(index);
MM = Month(index);
DD = Days(index);
hh = HH(index);
Hs1 = H_s(index);
Tp1 = T_p(index);
Dir1 = dir(index);
2 Kommentare
Bob Thompson
am 10 Mär. 2020
We're going to have a difficult time giving you a definitive answer to your question because we don't know what the file format that you're loading looks like. If you wanted to upload a sample of the data we might be able to help you more.
That being said, this should be relatively easy to check on your own. I'm assuming you can open the data file directly, so why not do so and check if the data you're capturing is looking at the correct values? Taking a glance at how you're capturing 'index' I do think you're going to run into a problem where it's not going to give you any sort of index results because you're looking at two different arrays. 'find' is not my specialty though.
As an alternative, with the assumption that all of your data is numeric, you could try doing some logic indexing with a single array instead.
YYMMDD = cell2mat(time); % We'll start from here.
data = [Hs{:,1},Tp{:,1},DIR{:,1},U_wind{:,1},V_wind{:,1}]; % Put all data into one array
logic = (YYMMDD(:,1) >= 1985 & YYMMDD(:,1) <= 2005)&((HH == 0)|(HH == 6)|(HH == 12)|(HH == 18));
% Create logic array for which rows we want
reduceddata = data(logic,:); % Put only desired data into a new reduced data array. Same column order
Antworten (0)
Siehe auch
Kategorien
Mehr zu Big Data Processing 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!