converting Excel formula to Matlab (adding two arrays different lengths)
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Engineer Undergoing
le 30 Juil 2021
Réponse apportée : dpb
le 30 Juil 2021
Hello everyone,
I am trying to convert this formula from excel to matlab but I couldn't as my attempts faild and I am no expert in matlab.
this is the Excel formula: the value of C4: =C3+B4 and continues to the end of the C column (450x1):
Note the first value on the C column has to be a zero, hence that's why i used zeros
my attempt on matlab:
EData = zeros(19857,1);
Data = idx + EData(1:end);
EData beign the C column and idx the B column
0 commentaires
Réponse acceptée
dpb
le 30 Juil 2021
C=[0;cumsum(B)];
where B is your variable in column B
MATLAB uses vector operations; to append a vector to a single value (or even another vector) just once, the explicit catenation shorthand using [] and ; is fast enough to not bother with the preallocation and explicit addressing of indices within the preallocated output array.
If one were doing this inside a for...end loop of significant size, then the preallocation step would be needed to prevent rapid performance degradation by the need for dynamic allocation and reallocation.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices 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!