For command + interpolation: need some tips
Show older comments
I have a matrix "A" with three columns: daily dates,prices,and hours - all same size vector - there are multiple prices associated to hours in a day.
For each date, hours repeat and I need to interpolate linearly prices that I don't have for some "wanted" hours. But of course I can't use the command interp1 if my hours repeats in my column because I have multiple days. So say:
new_timeinhr = 0:0.25:max(A(:,3); %I want my hours in 0.25unit increments (like 9.5hrs);
day_hour = rem(new_timeinhour, 24);
new_timeinhr( day_hour <= 9.2 | day_hour >= 16.1 ) = []; %here I want only prices between 9.5hours and 16hours
%I then create a unique vectors of day and want to use a for and if command to interpolate "daily" and then stack my new prices in a vector one after the other%
days=unique(A(:,1));
for j=1:length(days);
if A(:,1)==days(j);
int_prices(j) = interp1(A(:,2), A(:,3), new_timeinhr);
end;
end;
of course the error is now: In an assignment A(I) = B, the number of elements in B and I must be the same.
How can I write the int_prices(j) to stack?
Accepted Answer
More Answers (0)
Categories
Find more on Interpolation 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!