필터 지우기
필터 지우기

Finding row indices of a cell array containing a certain element

조회 수: 1 (최근 30일)
Gayan Lankeshwara
Gayan Lankeshwara 2022년 3월 9일
답변: Rik 2022년 3월 9일
I hae the following cell array.
arr = cell(4,1);
arr{1,1}=1:3:15;
arr{2,1}=2:2:20;
arr{3,1}=3:3:30;
arr{4,1}=0:4:10;
%% I need to find the row indices of cells containing the element '4', i.e., the output should be
% k = [1;2;4]

답변 (1개)

Rik
Rik 2022년 3월 9일
A simple loop should do:
arr = cell(4,1);
arr{1,1}=1:3:15;
arr{2,1}=2:2:20;
arr{3,1}=3:3:30;
arr{4,1}=0:4:10;
L=false(numel(arr),1);
for n=1:numel(arr)
L(n)=ismember(4,arr{n});
end
k=find(L)
k = 3×1
1 2 4

카테고리

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

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by