How to extrapolate between two 1x1000 matrixes in an more efficient way?
Show older comments
I have two matrixes that are dimensions 1X1000. Each matrix represents simulated revenues for one year, 1000 times per each year. Matrix A represents the year 2020 and matrix B the year 2025. I want to extrapolate between each element so that for instance the first simulation outcome in 2020 connects lineary to the first simulation outcome in 2025. So far I have coded this in this way:
% delta [2020-2025]
Delta_2020_2025CfD = zeros(1,1000);
for i =1:1000
for j=1:1
Delta_2020_2025CfD(j,i) = Aggregated_CfDRevenues2025(j,i) - Aggregated_CfDRevenues2020(j,i);
end
end
% delta per year
Year_differance = 5
Deltaperyear_2020_2025_CfD = zeros(1,1000);
for i =1:1000
for j=1:1
Deltaperyear_2020_2025_CfD (j,i) = Delta_2020_2025CfD (j,i) / Year_differance;
end
end
% extrapolated aggregated revenues [2021,2022,2023,2024]
ExAggRev_2021CfD = zeros(1,1000);
ExAggRev_2022CfD = zeros(1,1000);
ExAggRev_2023CfD = zeros(1,1000);
ExAggRev_2024CfD = zeros(1,1000);
for i =1:1000
for j=1:1
ExAggRev_2021CfD (j,i) = Aggregated_CfDRevenues2020(j,i) + Deltaperyear_2020_2025_CfD(j,i);
ExAggRev_2022CfD (j,i) = ExAggRev_2021CfD (j,i) + Deltaperyear_2020_2025_CfD(j,i);
ExAggRev_2023CfD (j,i) = ExAggRev_2022CfD (j,i) + Deltaperyear_2020_2025_CfD(j,i);
ExAggRev_2024CfD (j,i) = ExAggRev_2023CfD (j,i) + Deltaperyear_2020_2025_CfD(j,i);
end
end
%matrix revenues [2021 to 2024 inc]
Rev_CfD_2021to2024 = [ExAggRev_2021CfD; ExAggRev_2022CfD; ExAggRev_2023CfD; ExAggRev_2024CfD]
This works. However is there a smarter and more efficient way to do this? Like some Matlab function that I do not know of? I have looked at interp1 but I think this would not work in my case, since I am looking to have a fixed starting point (the revenues in 2020) and a fixed ending point (the revenues in 2024).
Thanks a lot!
Mak
P.S - I am new to Matlab :)
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements 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!