How do I input multiple values in an array/matrix multiple times?

36 visualizaciones (últimos 30 días)
Hello. I am trying to input multiple values in an array/matrix multiple times. So far I've tried using a for-loop but it only changes the values what's inside of the array instead of adding more. How do I do it?
% Get all complete rotations
cnt = 1;
ResEncoder = 8192;
for i = 2:1:lRawDat
if (abs(Value(i) - Value(i-1)) > (ResEncoder / 2))
% IdxStart indicates the start of each rotation
IdxStart(cnt) = i;
cnt = cnt + 1;
end
end
% Each cnt represents 1 rotation with values from 0-8191
d = zeros(cnt-1, 1);
for i = 1:1:cnt-1
a = Value(IdxStart(i):IdxStart(i+1)-1);
b = Time(IdxStart(i):IdxStart(i+1)-1);
c = polyfit(b,a,1);
d(i) = polyval(c,b);
end
I know this is not how it's supposed to be written. But are there any suggestions on how to do so?
Thank you very much!

Respuesta aceptada

KSSV
KSSV el 24 de Feb. de 2022
Save them into a cell.
d = cell(cnt-1, 1);
for i = 1:1:cnt-1
a = Value(IdxStart(i):IdxStart(i+1)-1);
b = Time(IdxStart(i):IdxStart(i+1)-1);
c = polyfit(b,a,1);
d{i} = polyval(c,b);
end
celldisp(d)

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by