Adding two arrays of different sizes together evenly without messing cumulative sum.
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Shahab Khan
le 24 Oct 2019
Modifié(e) : Shahab Khan
le 24 Oct 2019
I have 2 arrays.
A = [0 1 2 3 4 5 6 . . . . n] % Size 2402 x 1, assume in this case n number is 58
B = [18] % Size 1x1
C = [Cumulative output of A+B] % expected result starting from 0 and ending at 76 @ size of 2402 *1
Now
A is a cummulative sum of energy consumed starting from 0 and ending at 58 kWh during 2402 seconds.
B is total auxiliary energy consumed during 2402 seconds. Please note B is not a cumulative energy. Its just a number in 1 x 1 array.
What I am trying to do is to add B to A evenly such that the result C can be a cumulative result starting from 0 and ending at 76.
I tried a lot of logics but nothing worked for me.
Kindly guide me in correct direction to acheive this result.
0 commentaires
Réponse acceptée
Akira Agata
le 24 Oct 2019
Based on the question, C should be a cumulative result starting from 0. So, it should be:
C = A + linspace(0,B,length(A));
2 commentaires
Plus de réponses (1)
Walter Roberson
le 24 Oct 2019
Modifié(e) : Walter Roberson
le 24 Oct 2019
C = cumsum(A + B / length(A));
0 commentaires
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!