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 中查找有关 NaNs 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!