How can i extract Index values of different cell arrays

조회 수: 18 (최근 30일)
Ram
Ram 2018년 7월 29일
댓글: Ram 2018년 7월 30일
I want to extract the cell arrays w.r.to the index num,
for w =1:length(mydata)
%[~,I]= find(mydata{w, 2}(:,2)) = find(mydata{w, 1}(:,1));
for o = 1:length(mydata{w,2})
index = find(mydata{w, 2}(:,2) == mydata{w, 1}(:,1)== o);
mydata{w,3} = index;
end
end
I have a cell which contains max and its index values in each row. Now i want to find max index values in another cell and extract those values( matrix 1*2, here i want to extract only 1st col value only). for ex. [M,I] = [2,295]. 295 index value of its max value in certain row, let say (6,26321) is the extracted index value in another cell. extract value is 6(1st col) similarly all other row cells matrix. Thanks in advance.
  댓글 수: 5
Ram
Ram 2018년 7월 30일
@jonas thanks for your reply. From 1*2 matrix i have max and index values. for example(from data),(0.3076,690) is our max and index values. Now i want to extract the values from 999*2 matrix. where index is 690 ie.,(8.1510,110.9065). but here i want to extract first col only for each cell array matrix. i have same data for min and index values. later i want to find distance between them.
Ram
Ram 2018년 7월 30일
편집: Ram 2018년 7월 30일
@image analyst thanks for your support. above code writtens only my max and index values again, But this is not my required output. here input matrix is 1*2 which has [max ind] values. but we consider only index values in order to find index values in 999*2 matrix. as i said in above. And here other cell/rows cells means to find all index values for each cell (999*2) array from the 1*2 matrix. sorry for inconvienence about explanation.

댓글을 달려면 로그인하십시오.

채택된 답변

jonas
jonas 2018년 7월 30일
편집: jonas 2018년 7월 30일
Something like this should work.
s = load('mydata21.mat')
s=s.mydata21;
c=s(:,2) %arrays with indices
d=s(:,1) %arrays with values
out=cellfun(@(x,y)y(x(2),1),c,d)
  댓글 수: 6
jonas
jonas 2018년 7월 30일
편집: jonas 2018년 7월 30일
1. Cellfun is just a clean way of performing operation on multiple cells. In this case you can do the same with a simple loop:
%%Load data
s = load('mydata21.mat')
s=s.mydata21;
%%Preallocate
out=nan(length(s))
%%Loop over each row
for i=1:length(s)
out(i)=s{i,1}(s{i,2}(2));
end
2. If your data is already loaded, just delete the first line and replace the variable with whatever you call it? I suppose you should replace s by mydata?
3. In the cellfun or the loop, just change the column index from 1 to 2.
Ram
Ram 2018년 7월 30일
@jonas Thanks alot. You are just genius and saved my time.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by