Simplify a summation code with array position bounds.

Hi, I have the following example code for a summation. Is there a way to write to this any simpler. I tried using symsum, but it would not allow me to put the positions of an array as the bounds.
filename = 'test.xlsx';
fullpath = join([path, filename], "\");
time = xlsread(fullpath,1, 'A:A');
ID = xlsread(fullpath,1,'B:B');
Force = xlsread(fullpath,1,'C:C');
lastval = length(time);
P_t = zeros(0,lastval);
for position = 1:lastval
P = 0;
for pos = 1:lastval
P = (P + 2*time(position)*ID(pos));
end
P_t(position) = P;
end
Pt = P_t.';
xlswrite(fullpath,cellstr('P(t)'),1,'D2');
xlswrite(fullpath, Pt, 1, 'D3:D13');

답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Cell Arrays에 대해 자세히 알아보기

질문:

2020년 4월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by