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
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 个评论
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
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?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!