Calculate slope at specific time over many days using polyfit and for loop

4 次查看(过去 30 天)
I have a data set that show daily fluctuation in groundwater. I need to find the slope of the hydrograph every day between the hours of 4 and 12. I have tested this loop with other operators and they are working on the correct intervals. the hours 12 to 4 correspond to the first 17 rows of every 96 rows.
How do I correctly use polyfit to calculate slope during the assigned intervals?
The error I am recieving is as follows:
Unable to perform assignment because the indices on the left side are not compatible with the size of
the right side.
Error in ETg_toy (line 105)
tR(h)=polyfit(subset_day,subset_depth,1)
Below is the code I am trying to use:
load('GroundwaterDataA');
A = GroundwaterDataA;
depth=flip(A(:,2))
day=flip(A(:,1))
for h=1:200 %day day 200 = day 199
start2=(h*96)-15;
endp2=h*96;
subset_depth=depth(start2:endp2)
subset_day=day(start2:endp2)
tR(h)=polyfit(subset_day,subset_depth,1)
pause
end

采纳的回答

Star Strider
Star Strider 2019-9-14
You appear to be calculating them correctly, just not storing them correctly. For a linear fit, polyfit will produce a (1x2) vector of the coefficients.
Try this:
tR(h,:)=polyfit(subset_day,subset_depth,1)
Note the added dimension.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by