필터 지우기
필터 지우기

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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by