Borrar filtros
Borrar filtros

converting Excel formula to Matlab (adding two arrays different lengths)

1 visualización (últimos 30 días)
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

Respuesta aceptada

dpb
dpb el 30 de Jul. de 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.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by