How to access the index of the cell elements
조회 수: 120 (최근 30일)
이전 댓글 표시
Hey all,
Hope everyone doing good. I have a small doubt in accessing the index of a cell element in a cell array.
I have a cell array,
A = {1 2 'Node1'; 3 4 'Node2'};
p = cell2mat(X(:,1));
%q = cell2mat(X(:,2));
disp(p);
%disp(q);
T_Vorgabe = zeros(1,length(f));
for plotnumber = 1:n
c = find(p == plotnumber,1);
if ~isempty(c)
c = plotnumber;
% Here I need to get the index of the cell element, which means plotnumber or p.
end
end
My question is how to find the index of the cell element of a first column.
for an example if plotnumber is 3, index of 3 is 2,1.
Any suggestions and answered are most welcomed
Thanks in advance
댓글 수: 2
KALYAN ACHARJYA
2019년 6월 29일
Suppose a cell array
sanmple_stuc={[1 2 3 4],[4 5 6],[ 6 7 8]}
Now you are looking for the index of respective array element? Yes, plear clarify?
Say 6 is which which cell array and respective index positions??
답변 (1개)
Vimal Rathod
2019년 7월 16일
Hi I understand that you want to find the index of any element in a cell and from the example you gave, I assume that the element whose index to find is a number. You can use the “find function” to find the element index in the cell array.
% Making a cell as an array using [A{:}].
% Using find function on that can help you out.
A = {1,2,'Node1';3,4,'Node2'};
% this will return the index 2 which is a matlab version of indexing
%Using column first and row as the second input as ':' operator prints
%the cell in column major order.
[column,row] = find([A{:}] == 3);
You can refer the find function documentation here
You can also refer to a similar problem here
If you want to find the index of string in the cell you can use “for loop” to loop through the elements.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!