For command + interpolation: need some tips

조회 수: 1 (최근 30일)
Charles Martineau
Charles Martineau 2012년 6월 7일
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?

채택된 답변

Charles Martineau
Charles Martineau 2012년 6월 7일
I think I solved it doing it this way:
new_timeinhr = 0:0.25:max(A(:,2));
day_hour = rem(new_timeinhr, 24);
new_timeinhr( day_hour <= 9.4 | day_hour >= 16.1 ) = [];
days=unique(data(:,1));
P=[];
for j=1:length(days);
condition=A(:,1)==days(j);
intprices = interp1(A(condition,2), A(condition,3), new_timeinhr);
P=vertcat(P,intprices');
end;

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by