Hi, I am working on data which resembles like below:
B=
-0.013925234 2.83821
-0.036085514 1.61022
-0.046681829 0.97135
-0.046968672 0.89513
-0.024245858 1.81864
0.01516536 3.87455
0.041675541 5.43357
0.051087392 6.08749
0.041758625 5.71526
0.017252935 4.49994
-0.014129511 2.82299
-0.036253916 1.60009
-0.047028757 0.96068
-0.047154755 0.88619
-0.024045187 1.81487
0.015306466 3.87658
0.041772875 5.43423
0.051511911 6.10654
0.042270005 5.73995
0.017497553 4.51872
-0.013852278 2.84432
-0.035969299 1.61081
-0.046629988 0.97547
-0.046837352 0.90091
-0.024421296 1.80676
0.015151971 3.87475
0.042088386 5.44538
0.051397067 6.10449
0.042292149 5.73531
0.017802252 4.521
-0.013961625 2.82833
-0.036328589 1.60363
I have thousands of such values. The problem is that I have to look for the minimum value in the first column and starting from that going forward until I get another minimum value (as close as possible to the first one) and separate the corresponding elements in both columns. This process has to be repeated over the whole data. So if I look at the given data, this is how output will look like:
a =
-0.046968672 0.89513
-0.024245858 1.81864
0.01516536 3.87455
0.041675541 5.43357
0.051087392 6.08749
0.041758625 5.71526
0.017252935 4.49994
-0.014129511 2.82299
-0.036253916 1.60009
-0.047028757 0.96068
-0.047154755 0.88619
b =
-0.047154755 0.88619
-0.024045187 1.81487
0.015306466 3.87658
0.041772875 5.43423
0.051511911 6.10654
0.042270005 5.73995
0.017497553 4.51872
-0.013852278 2.84432
-0.035969299 1.61081
-0.046629988 0.97547
-0.046837352 0.90091
Is there any tool / method available in matlab for such a task?

 Réponse acceptée

John BG
John BG le 19 Déc 2016
Waqar
It seems you have the input and output signals of an amplifier.
The way to solve this question is to
1.- invert the first column of B
2.- find mins by spotting peaks of inverted signal with findpeaks
3.- apply the location of found peaks to the original image
One can always build a custom function but there is standard no valleys function or minsearch option in function findpeaks .
Before trying point one I found command cummin, but Cumulative minims search command cummin doesn't help that much because is returns clusters of minims rather than the minims you want
B=[-0.013925234 2.83821
-0.036085514 1.61022
-0.046681829 0.97135
-0.046968672 0.89513
-0.024245858 1.81864
0.01516536 3.87455
0.041675541 5.43357
0.051087392 6.08749
0.041758625 5.71526
0.017252935 4.49994
-0.014129511 2.82299
-0.036253916 1.60009
-0.047028757 0.96068
-0.047154755 0.88619
-0.024045187 1.81487
0.015306466 3.87658
0.041772875 5.43423
0.051511911 6.10654
0.042270005 5.73995
0.017497553 4.51872
-0.013852278 2.84432
-0.035969299 1.61081
-0.046629988 0.97547
-0.046837352 0.90091
-0.024421296 1.80676
0.015151971 3.87475
0.042088386 5.44538
0.051397067 6.10449
0.042292149 5.73531
0.017802252 4.521
-0.013961625 2.82833
-0.036328589 1.60363]
figure(1)
yyaxis left;plot(B(:,1)')
yyaxis right;plot(B(:,2)')
grid on
a =[-0.046968672 0.89513
-0.024245858 1.81864
0.01516536 3.87455
0.041675541 5.43357
0.051087392 6.08749
0.041758625 5.71526
0.017252935 4.49994
-0.014129511 2.82299
-0.036253916 1.60009
-0.047028757 0.96068
-0.047154755 0.88619]
figure(2)
yyaxis left;plot(a(:,1)')
yyaxis right;plot(a(:,2)')
grid on
d=cummin(B(:,1)')
B1=B(:,1)';B2=B(:,2)';
nd=0;for k=1:1:numel(d) v0=find(B1==d(k));nd=[nd v0]; end;
figure(3);plot(B(:,1),'b');hold all;plot(B(:,2),'r');legend('B 1st column','B second column');grid on
hold all;figure(3);plot(nd+1,B1(nd+1),'bo')
1.- Inverting input signal
B1max=max(B1);
B1inv=B1max-B1;
2.- spotting mins
[mins locmins]=findpeaks(B1inv);
3.- Applying found mins to signal
1st cycle of input signal:
B1([locmins(1):1:locmins(2)])
=
Columns 1 through 3
-0.046968672000000 -0.024245858000000 0.015165360000000
Columns 4 through 6
0.041675541000000 0.051087392000000 0.041758625000000
Columns 7 through 9
0.017252935000000 -0.014129511000000 -0.036253916000000
Columns 10 through 11
-0.047028757000000 -0.047154755000000
1st cycle of output signal, the one you are asking for
B2([locmins(1):1:locmins(2)])
=
Columns 1 through 3
0.895130000000000 1.818640000000000 3.874550000000000
Columns 4 through 6
5.433570000000000 6.087490000000000 5.715260000000000
Columns 7 through 9
4.499940000000000 2.822990000000000 1.600090000000000
Columns 10 through 11
0.960680000000000 0.886190000000000
2nd cycle of the output signal:
B2([locmins(2):1:locmins(3)])
=
Columns 1 through 3
0.886190000000000 1.814870000000000 3.876580000000000
Columns 4 through 6
5.434230000000000 6.106540000000000 5.739950000000000
Columns 7 through 9
4.518720000000000 2.844320000000000 1.610810000000000
Columns 10 through 11
0.975470000000000 0.900910000000000
.
Waqar
if you find my answer useful would you please mark it as Accepted Answer.
To any other reader, please if you find this answer of any help, please click on the thumbs-up vote link,
thanks in advance for time and attention
John BG

Plus de réponses (1)

Image Analyst
Image Analyst le 19 Déc 2016
B is your input data. So you find the min of its column #1. Then extract from that row downwards, and find the min in that subset. Then extract another subset, and so on. OK, fine. Easy enough.
B=[...
-0.013925234 2.83821
-0.036085514 1.61022
-0.046681829 0.97135
-0.046968672 0.89513
-0.024245858 1.81864
0.01516536 3.87455
0.041675541 5.43357
0.051087392 6.08749
0.041758625 5.71526
0.017252935 4.49994
-0.014129511 2.82299
-0.036253916 1.60009
-0.047028757 0.96068
-0.047154755 0.88619
-0.024045187 1.81487
0.015306466 3.87658
0.041772875 5.43423
0.051511911 6.10654
0.042270005 5.73995
0.017497553 4.51872
-0.013852278 2.84432
-0.035969299 1.61081
-0.046629988 0.97547
-0.046837352 0.90091
-0.024421296 1.80676
0.015151971 3.87475
0.042088386 5.44538
0.051397067 6.10449
0.042292149 5.73531
0.017802252 4.521
-0.013961625 2.82833
-0.036328589 1.60363];
startingRow = 1;
[rows, columns] = size(B)
% Get the min of column 1
[minValues(1), indexesOfMins(1)] = min(B(startingRow:end));
fprintf('The first min = %f and occurs at row %d.\n', minValues(1), indexesOfMins(1));
for k = 2 : rows
% Start searching from the last min downwards.
startingRow = indexesOfMins(k-1)+ 1;
% Get the min of column 1
[minValues(k), indexesOfMins(k)] = min(B(startingRow:end));
% Add in the offset
indexesOfMins(k) = indexesOfMins(k) + startingRow - 1;
fprintf('The #%d min = %f and occurs at row %d.\n', k, minValues(k), indexesOfMins(k));
% Break if we've hit the end of the column
if indexesOfMins(k) >= rows
break;
end
end
minValues
indexesOfMins
msgbox('Done!');
But what are your outputs, the badly-named "a" and "b" ???

1 commentaire

Waqar Qureshi
Waqar Qureshi le 19 Déc 2016
Yes. I have to later on interpret this data. I am trying to test your solution. Thanks

Connectez-vous pour commenter.

Catégories

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by