필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Center of repeatative/duplicate values in Matlab

조회 수: 1 (최근 30일)
Koustubh Shirke
Koustubh Shirke 2020년 3월 14일
마감: MATLAB Answer Bot 2021년 8월 20일
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 .

답변 (2개)

Ameer Hamza
Ameer Hamza 2020년 3월 14일
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 2020년 3월 14일
편집: dpb 2020년 3월 14일
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
>>

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by