How to access the index of the cell elements
196 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
surendra kumar Aralapura mariyappa
el 29 de Jun. de 2019
Respondida: Vimal Rathod
el 16 de Jul. de 2019
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 comentarios
KALYAN ACHARJYA
el 29 de Jun. de 2019
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??
Respuestas (1)
Vimal Rathod
el 16 de Jul. de 2019
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 comentarios
Ver también
Categorías
Más información sobre Data Types en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!