For command + interpolation: need some tips
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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?
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!