필터 지우기
필터 지우기

Get the index of one cell of a cell array

조회 수: 4 (최근 30일)
Nicolas Douillet
Nicolas Douillet 2020년 5월 4일
댓글: Ameer Hamza 2020년 5월 5일
Hi,
From a given cell of a cell array, how is it possible to easily and quickly get its index ?
Thanks for help.
Best.
  댓글 수: 2
Johannes Hougaard
Johannes Hougaard 2020년 5월 4일
Try reading the help for ind2sub or sub2ind
These functions are valid for cell arrays as well.
Nicolas Douillet
Nicolas Douillet 2020년 5월 4일
편집: Nicolas Douillet 2020년 5월 4일
Ok thanks for your reply, but I forgot to mention this is for one dimension cell arrays in my case.

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

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 5월 4일
Suppose you have a cell array
A = {1,2,3,4,5};
and you extract a specific element of this array
a = A(4);
then, for a general case, you can find its index back using
idx = find(cellfun(@(x) isequal(x,a{:}), A))
if all the elements of A are scalar, then you can also write
idx = find([A{:}]==a{1});
  댓글 수: 2
Nicolas Douillet
Nicolas Douillet 2020년 5월 5일
Great, thank you for this very clear answer.
This is the kind of solution I was looking for.
Ameer Hamza
Ameer Hamza 2020년 5월 5일
I am glad to be of help.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by