Add increasing values within an array

1 回表示 (過去 30 日間)
Ole Braunholz
Ole Braunholz 2022 年 10 月 28 日
コメント済み: Voss 2022 年 11 月 1 日
Hello, I have the following problem:
I get data of the angle of rotation of a screwdriver. Within a screw joint, the angle of rotation is reset to zero at a point in time. This can happen any number of times during a pass. Example:
1°,5°,10°,12°,1°,5°,10°,12°,1°,5°,10°,12°. The numbers are only exemplary.
I would like to merge the values now to a continuous data series. At the moment I have this code:
I hope I was able to describe the problem understandably. Many thanks
clear;
w=[1;2;3;1;2;3;1;2;3]; % Example Data
W=[];
for n=1:1:length(w)
if n==1
W(n)= 0; % 0 corresponds to: angle not reset
elseif n==max(length(w))
W(n)= 0;
elseif w(n)== w(n+1)
W(n)=0;
elseif w(n)>w(n-1)
W(n)=0;
elseif abs(w(n)-w(n-1))<-2
W(n)=0
elseif w(n)<w(n-1) % 1 corresponds to: Angle reset
W(n)=1;
end
end
  4 件のコメント
Ole Braunholz
Ole Braunholz 2022 年 10 月 28 日
The Output should be: [1,2,3,4,5,6,7,8,9]
Star Strider
Star Strider 2022 年 10 月 28 日
I still do not understand.

サインインしてコメントする。

採用された回答

Voss
Voss 2022 年 10 月 28 日
w=[1;2;3;1;2;3;1;2;3];
w_new = zeros(size(w));
w_new(1) = w(1);
offset = 0;
for ii = 2:numel(w)
if w(ii) < w(ii-1)
offset = w_new(ii-1);
end
w_new(ii) = w(ii)+offset;
end
w_new
w_new = 9×1
1 2 3 4 5 6 7 8 9
  2 件のコメント
Ole Braunholz
Ole Braunholz 2022 年 10 月 28 日
Perfect! Thanks a lot :)
Voss
Voss 2022 年 11 月 1 日
You're welcome!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeChemistry についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by