Zeros between Sign Change of Values in column
3 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Jan
on 15 Apr 2021
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 Comments
Jan
on 16 Apr 2021
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].
More Answers (2)
Mathieu NOE
on 14 Apr 2021
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 Comment
Tommy Schumacher
on 14 Apr 2021
Edited: Tommy Schumacher
on 14 Apr 2021
1 Comment
Mathieu NOE
on 15 Apr 2021
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
See Also
Categories
Find more on Graphics Object Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!