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