Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Center of repeatative/duplicate values in Matlab

1 visualización (últimos 30 días)
Koustubh Shirke
Koustubh Shirke el 14 de Mzo. de 2020
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
Hi,
I have a vector lik A = [1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 ]. I want to get index of centre and its value fo this vector. How can i do that In matlab scirpt ?
The solution of above problem should be.
values = [1 2 3];
Centre_Index = [3 8 14 ];
Thanks in adavnce .

Respuestas (2)

Ameer Hamza
Ameer Hamza el 14 de Mzo. de 2020
x = [1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 ];
indexes = [1 find(x(2:end) - x(1:end-1))+1 numel(x)];
indexes = floor(movmean(indexes, 2, 'Endpoints', 'discard'));

dpb
dpb el 14 de Mzo. de 2020
Editada: dpb el 14 de Mzo. de 2020
val=unique(A);
iC=arrayfun(@(x) median(find(A==x)),val);
for your A above
>> val=unique(A);
>> iC=arrayfun(@(x) median(find(A==x)),val)
iC =
3 8 14
>>

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by