converting Excel formula to Matlab (adding two arrays different lengths)
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
dpb
2021 年 7 月 30 日
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!