フィルターのクリア

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 Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by