how can i find the slope for every six rows of my data

1 次查看(过去 30 天)
I have data with 57.000 rows [Windspeed and time] and I want to calculate the rate of change or the slope of the windspeed for every six rows because 6 rows completes 1 hour. What fuction is possible to use for the rate of change or the slope? my final answer will be 57000/6=9500 rows or columns.

采纳的回答

Star Strider
Star Strider 2018-1-8
One approach:
WindTime = [(0:(1/6):5-(1/6))' rand(30,1)]; % Time (Col#1), Velocity (Col#2)
WindReshape = reshape(WindTime(:,2), 6, []); % Reshape Velocity Data Only
B = [WindTime(1:6,1) ones(6,1)]\WindReshape; % Estimate Slope & Intercept
SlopeVector = B(1,:); % Save Slopes
The code reshapes your velocity data only into a 6-row, ‘N’-column matrix. It then calculates the slope and intercept (for uniformity using the first hour only for the time vector, rather than each successive hour), and then calculates the slope and intercept in matrix ‘B’. As I coded it, the slope is the first row, so extracting that gives the slopes for each hour segment. (It assumes that there are no missing or non-finite data, and does not check for those possibilities.)
If you copy your data array to ‘WindTime’, you can likely use my code without further changes.
  2 个评论
Olger Papa
Olger Papa 2018-1-9
编辑:Olger Papa 2018-1-9
I don't understand why rand(30,1), i think the final answer of the slope will be 9500 rows or columns because 57000/6=9500. Thank sou for your effort. I want something like that
but for every six rows
Star Strider
Star Strider 2018-1-9
As always, my pleasure.
The rand call was to create a matrix to test my code. (If possible, I always test my code before posting it.)
Note that in my ‘WindTime’ matrix, I have time in the first column and wind velocity in the second column. You will need to change the column references in my code to work with the Excel spreadsheet you read into your workspace.

请先登录,再进行评论。

更多回答(1 个)

John Harris
John Harris 2018-1-8
Your formula will depend on what kind of answer you want, but I think simple math operators will do most of the work for you.
Rate of change is (windspeed2-windspeed1)/(time2-time1) ... but if you apply this to every 6th entry, you're throwing away a lot of data. What if the wind is still at the top 'o the hour, but 10 knots in opposite directions every half hour?
Perhaps you want to calculate the rate for each measurement, then take an average for each 1-hour period?
  1 个评论
Olger Papa
Olger Papa 2018-1-9
I thing you're right my question it was not clearly enough. I want the final answer to be slope=57000/6=9500 rows or columns.
Something like that but for for every six rows.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by