Find cell in array that contains the values x and y
    1 Ansicht (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    Hannes Frey
 am 28 Jun. 2021
  
    
    
    
    
    Kommentiert: Hannes Frey
 am 29 Jun. 2021
            I have a cell array r that contains a set of indizes in each cell
r = {(1 5 6), (7 10 9 8), (2 3 4}
I want to find the index of the cell that contains e.g. the values x  = 10 and y = 7
Hence the answer should be 2 
How would I go about to do this? 
Thank you for you help and best wishes 
0 Kommentare
Akzeptierte Antwort
  Loubna Baroudi
 am 28 Jun. 2021
        Hi,
index = cellfun(@(x) find(x==7) & find(x==10), r, 'UniformOutput', false)
it will output a cell: {[],1,[]}
0 Kommentare
Weitere Antworten (1)
  Soniya Jain
    
 am 28 Jun. 2021
        Hi, you can try these lines of code,
r = {{1,5,6} {7,10,9,8} {2,3,4}};
for i = 1:3
    j = size(r(1,i));
    flag = 0;
    for k = 1:j
        if (r{1,i}{1,k} == 7) && (r{1,i}{1,k} == 9)
            flag = 1;
            break;  % will break inner for loop
        end
    end    
    if flag == 1
        break;   % will break outer for loop
    end
    index = i;
end    
Siehe auch
Kategorien
				Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


