Create cell array of column indices of a specific string
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi,
I have a 5x1 cell array ,g, where each cell is 40x50. I want to find the column indices of the string 'Latitude' in each of the cells in the cell array. I know there is 7 occurences of this string in each of the cells but I want the code to tell me that. My desired output is a new cell array where each cell contains the column indices of this string (so it will end up being a 5x1 cell array where each cell contains the 7 column indices). I tried this:
ind=find(~cellfun('Latitudes', g));
but it won't work. Any suggestions would be much appreciated
Thank you
댓글 수: 0
채택된 답변
Voss
2022년 6월 22일
% make cell array g
g = repmat({repmat({''},40,50)},5,1);
% put 7 random 'Latitude's in each cell
for ii = 1:5
g{ii}(randi(2000,7,1)) = {'Latitude'};
end
% get the column index of each instance of 'Latitude'
cidx = cellfun(@get_latitude_columns,g,'UniformOutput',false)
% put them together in a matrix, if you prefer
% (5x7 or 7x5, whatever makes sense to you)
cidx = [cidx{:}].'
function idx = get_latitude_columns(s)
[~,idx] = find(strcmp(s,'Latitude'));
end
댓글 수: 6
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!