Selecting particular data range from matrix

4 views (last 30 days)
Mark Twen
Mark Twen on 12 May 2015
Edited: Michael Haderlein on 12 May 2015
Hello.I have got problem while selecting particular data range from my wind data,which includes approximately 884000 rows and 7 columns(1st column=station number,2nd column = year,3rd column= month,4th column=day,5th column = hour,6th column = speed,7th column = direction).I am trying to select speed according to particular station=>year=>month=>day=>hour.I wrote own code,but i think i do something wrong.Can anybody help me to solve this?I put piece of data and own code in order to show how my data is looks like.
fileID=fopen('wind.txt'); data=textscan(fileID,'%d %d %d %d %d %d %s'); fclose(fileID); Station=input('Enter station number = '); Year=input('Enter year = '); Month=input('Enter month = '); Day=input('Enter day = '); Hour=input('Enter hour = '); S=[]; Y=[]; M=[]; D=[]; H=[]; Spd=[]; Dir=[];
(data{1,1}==Station) & (data{1,2}==Year) & (data{1,3}==Month) & (data{1,4}==Day) & (data{1,5}==Hour); S=find(data{1,1}==Station); Y=find(data{1,2}==Year); M=find(data{1,3}==Month); D=find(data{1,4}==Day); H=find(data{1,5}==Hour); Spd=data{1,6}(H); Dir=data{1,7}(H);
%Average speed
Average_speed = mean(Spd)
%Produced power r=60; A=360; v=Average_speed; Produced_power = 0.5*r*A*v.^3
%

Answers (1)

Michael Haderlein
Michael Haderlein on 12 May 2015
No data is available and the code is not formatted. Please use the {}Code button for proper code formatting and please not only select your data but also upload it.
I guess you can simplify your code by using textscan(fileID, format, 'collectoutput', 'true' ). Then you can easily access the "identifier" of your data (e.g. [1 2015 5 12 8]) as member of the submatrix data(:,1:5). Use ismember() for this.
  2 Comments
Mark Twen
Mark Twen on 12 May 2015
Excuse me, i did not understand you.My matlab knowledges are not so good. I have searched some informations about ismember(),and none of them matches with mine.In my project i want to take particular range of data,and the ranges of data will be specified by me.For example: i want to know the average speed of wind which corresponds to station number 17840,year 1994,month 5,day 5,hour 6.How can i do that.Can you look into my code,what exactly i do wrong?Can you give similar examples to do that.
Michael Haderlein
Michael Haderlein on 12 May 2015
Edited: Michael Haderlein on 12 May 2015
You access your data with
datac=textscan(fileID,format,'collectoutput',true);
data=datac{1};
Maybe your data looks like this.
1 2015 3 14 8 4.12 91.54
1 2015 3 14 9 4.27 88.31
1 2015 3 14 10 6.37 90.47
1 2015 3 14 11 5.16 91.46
2 2015 3 14 8 8.12 12.42
2 2015 3 14 9 3.27 65.19
2 2015 3 14 10 2.37 50.77
2 2015 3 14 11 1.16 35.63
1 2015 3 15 8 1.37 13.78
1 2015 3 15 9 1.41 64.13
1 2015 3 15 10 0.89 16.54
1 2015 3 15 11 1.01 34.45
2 2015 3 15 8 0.37 53.86
2 2015 3 15 9 0.41 84.38
2 2015 3 15 10 1.89 56.45
2 2015 3 15 11 0.01 43.52
So you have two stations, data from 14th and 15th of March this year and only for 8-11 am. If I got you right, you want for instance the speed and direction for the second station at March 14th at 9 am, right? Then, your search pattern is
inp=[2 2015 3 14 9];
and you find the corresponding values with
[~,ind]=ismember(data(:,1:5),inp,'rows');
data(ind==1,6:7)
ans =
3.2700 65.1900
Which is speed/velocity at said station/time.

Sign in to comment.

Categories

Find more on Oceanography and Hydrology in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!