Working only with the equal values based on columns

1 visualización (últimos 30 días)
Bianca Brisc
Bianca Brisc el 2 de Sept. de 2021
Respondida: Brunno Machado de Campos el 19 de Oct. de 2021
Hello
I have a database similar to this example:
Where my last two columns are pixel position.
I want to average only the beams for which the last two column are equal. So for example row 2 and row 3 have the same values in the last two column -> I average the rest of the columns.
Row 1 and 6 have the same values in the last two columns -> I average the rest of the columns.
Row 1 and 2 do not have the same values in both of the last two columns -> I do not average the rest of the columns.
Any ideas?Thank you!
152.8357 164.3893 126.34 131.65 125.78 125.55 120.85 NaN 25 73
149.288 NaN 132.42 140.36 138.26 140.65 142.57 NaN 25 74
159.8254 NaN 123.74 140.59 135.69 143 NaN NaN 26 74
152.828 NaN 127.59 136.16 124.92 125.11 119.38 NaN 27 69
139.56 141.28 127.75 129.74 124.24 109.4 NaN 118.84 27 69
129.69 158.8131 153.6606 127.84 122.14 NaN 127.76 131.23 27 73

Respuestas (1)

Brunno Machado de Campos
Brunno Machado de Campos el 19 de Oct. de 2021
Hi Bianca, until that 'single line answer' does not pop up, try using this:
aa = Table; %Your table
eqs = aa(:,end-1:end);
idx = 0;
Exc = [];
for i = 1:size(eqs,1)
if ~any(i==Exc)
Tvg = prod(eqs(i,:)==eqs,2);
idx = idx + 1;
Final(idx,:) = nanmean(aa(find(Tvg),:),1); % nanmean because you have NaNs in your example
Exc = [Exc,find(Tvg)'];
end
end
Your final table, I belive will be the "Final" var.
Best

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by