Zeros between Sign Change of Values in column
2 ビュー (過去 30 日間)
古いコメントを表示
Hello,
i have a matrix A (1080x2). In the 2. Column i have values which contains sign changes
1.Column 2. Column
1 0
2 0
3 0.00047
4 -0.0177
5 -0.0328
6 0.0075
7 0
8 -0.0170
9 0
10 0
The values between sign changes in 2. column should be zero and keep the first value of sign change
1.Column 2. Column
1 0
2 0
3 0
4 -0.0177
5 0
6 0.0075
7 0
8 -0.0170
9 0
10 0
Maybe helpful is this Question/Answer:
Thank You
0 件のコメント
採用された回答
Jan
2021 年 4 月 15 日
data = [ ...
1 0; ...
2 0; ...
3 0.00047; ...
4 -0.0177; ...
5 -0.0328; ...
6 0.0075; ...
7 0; ...
8 -0.0170; ...
9 0; ...
10 0];
idx = [true; diff(data(:, 2) >= 0) == 0];
data(idx, 2) = 0
2 件のコメント
Jan
2021 年 4 月 16 日
Does this comment mean, that you want to treat the zero in another way?
Then please post an exhaustive set of input data to define uniquely, what you want to achieve. What is the wanted output for:
[-2, -1, 0, -1, -2]
[-2, -1, 0, 1, -2]
[1, 1, 0, 1, 1]
[1, 1, 0, -1, -1]
It is not automatically clear, how you want to treat the zeros or where the "sign change" occurs in [-1, 0, 1].
その他の回答 (2 件)
Mathieu NOE
2021 年 4 月 14 日
hello
this is my suggestion below + see attachements
data = importdata('data.txt');
x = data(:,1);
y = data(:,2);
threshold = 0; %
[t0_pos,s0_pos,t0_neg,s0_neg]= crossing_V7(y,x,threshold,'linear'); % positive (pos) and negative (neg) slope crossing points
% t0 => corresponding time (x) values
% s0 => corresponding function (y) values , obviously they must be equal to "threshold"
figure(1)
plot(x,y,t0_pos,s0_pos,'+r',t0_neg,s0_neg,'+g','linewidth',2,'markersize',12);grid on
legend('signal','positive slope crossing points','negative slope crossing points');
% now let's force y values to be zero when x values are one step before positive and negative slope zero crossing points
dx = mean(diff(x)); % x axis spacing
indp_before= floor(t0_pos/dx); % index of values before positive slope zero crossing points
indn_before= floor(t0_neg/dx); % index of values before negative slope zero crossing points
yy = y;
yy(indp_before)= 0;
yy(indn_before)= 0;
figure(2)
plot(x,y,x,yy,t0_pos,s0_pos,'+r',t0_neg,s0_neg,'+g','linewidth',2,'markersize',12);grid on
legend('signal','signal modified','positive slope crossing points','negative slope crossing points');
1 件のコメント
Tommy Schumacher
2021 年 4 月 14 日
編集済み: Tommy Schumacher
2021 年 4 月 14 日
1 件のコメント
Mathieu NOE
2021 年 4 月 15 日
hmm , I am not sure to understand the issue
I exported the original (first column) and modified signal (second column) in the attached excel file
can you add a 3rd column with the expected results ?
thanks
参考
カテゴリ
Help Center および File Exchange で Graphics Object Programming についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!