フィルターのクリア

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

16 ビュー (過去 30 日間)
Michael Arvin
Michael Arvin 2022 年 2 月 24 日
回答済み: KSSV 2022 年 2 月 24 日
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!

採用された回答

KSSV
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 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by