필터 지우기
필터 지우기

How to find the location of a minimum value in cell array?

조회 수: 2 (최근 30일)
Matt Learner
Matt Learner 2012년 11월 28일
댓글: Walter Roberson 2015년 8월 26일
consider the following example, Suppose if I have a cell notation
q=cell(5,1);
And if I have different dimensions for each cell, for example
q{1} = [6 7 9 4 0 0 1 2 3 1];
q{2} = [3 5 0 4 0 0 1 2 8 1];
q{3} = [3 5 0 5 4 3 4 2 6 4 0 0 1 2 8 1];
q{4} = [4 0 0 1 2 8 1];
q{5} = [4 0 0 0 2 8];
Now if I wish to find the latest cell location containing minimum non zero value, How can I find it?
In the above example, minimum non zero value is 1 and it is present in all cells, that is, q{1} q{2} q{3} q{4} except q{5}. So here the latest cell containing 1 is q{4} and 1 is located at 4th and 7th place of q{4}. I wish to get the location details mentioning that value 1 is present in q(4,4) and q(4,7). How can I find that?

채택된 답변

Matt Fig
Matt Fig 2012년 11월 28일
L = cellfun(@(x) find(x==1),q,'Un',0);
Now L has all the information you need.
  댓글 수: 14
nadia nadi
nadia nadi 2015년 8월 26일
Dear,
if I want to find minimum matrix from this code what should I do. I tried your code but I couldn't fit it to my code. I have many matrices when I want to find the maximum one by using the size I get the right answer but for minimum matrix I got empty matrix. I used this code
for i=1:10
MaxSubmat=load('MaxSubmatfile.txt');
Remind=load('Remindfile.txt');
ee{i}=MaxSubmat;
aa{i}=Remind;
end
[SizeMaxSubmat,MaxSubmat1]=max(cellfun(@(x) size(x,2),ee ))
[SizeRemind, Remind1]=min(cellfun(@(x) size(x,2),aa ))
MaxSub=ee{MaxSubmat1};
Reminder=aa{Remind1};
sizeReminder=size(Reminder,2)
I don't why it give give Reminder=[] and sizeReminder= 0 for while I know is more than one. could you please help me with this code I will appreciate that a lot.
regards, Nadia
Walter Roberson
Walter Roberson 2015년 8월 26일
You are load()'ing the same file each time, and it has no data in it.

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

추가 답변 (1개)

Vishal Rane
Vishal Rane 2012년 11월 28일
The first thing that comes to mind is
find(q{n} > 0)
It will you give you locations of elements matching the condition ' > 0' in q{n}, else it returns empty.
You could use that to build your logic.
Refer Link for examples on the find command.

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by