How to access the index of the cell elements
119 次查看(过去 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!