필터 지우기
필터 지우기

Select first max value of each cell at a cell array.

조회 수: 2 (최근 30일)
Dimitris Kokkinos
Dimitris Kokkinos 2014년 5월 2일
편집: Azzi Abdelmalek 2014년 5월 2일
Hi!I have a cell array named "GroupyDir" nx1 which has specified number of n cells at each run of my code.I need to make a vector with max values of each cell, which seems easy, but the problem is that I have the maximum value at 2 spots in some cells.I need my code to select the first appearence of the max value.I also need the index of the value selected at each cell.How can I do that?
I use this loop.
maxval=zeros(length(GroupyDir),1); maxposition=zeros(length(GroupyDir),1);
for i = 1:length(GroupyDir) maxval(i)=max(GroupyDir{i}(:,1)); maxposition(i)=GroupyDir{i}(find([GroupyDir{i}]==maxval(i)),2); end
PS:GroupyDir's cells have 2 columns.The first has some measurements and the second their indices at the time series I use as input data at my code.Thnx in advance.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 5월 2일
편집: Azzi Abdelmalek 2014년 5월 2일
a={[2 4 2 3 4] [0 2 6 4 0 6 1]}
n=numel(a);
maxval=zeros(1,n);
idx=zeros(1,n);
for k=1:numel(a)
[ii,jj]=max(a{k})
idx(k)=jj
maxval(k)=ii
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by