How do I input multiple values in an array/matrix multiple times?
10 ビュー (過去 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!