Separating elements from a column
Ältere Kommentare anzeigen
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?
Akzeptierte Antwort
Weitere Antworten (1)
Image Analyst
am 19 Dez. 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 Kommentar
Waqar Qureshi
am 19 Dez. 2016
Kategorien
Mehr zu AI for Signals finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

