How do I input multiple values in an array/matrix multiple times?
9 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
采纳的回答
KSSV
2022-2-24
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)
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multidimensional Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!