如何从单元格数中找到行数和列数

how can I find number of row and column from number of cell

请告诉我如何从单元格数中找到行数和列数。例如第 12 个单元格的行和列是 1 和 3。还有关于 3D 矩阵

你必须小心单元格的概念,在 Matlab 中单元格是它们自己的结构。

也就是说,您希望将线性索引转换为子索引,这是通过 ind2sub 函数完成的:

A=magic(4); %create 4x4 magic matrix

subidx=find(A==2); %subindex of the value 2, returns 5 

[i,j]=ind2sub(size(A),subidx)

returns

i =

     1


j =

     2

这是基础知识,不是 MatLab 特定的第 12 个单元格将是 9 行 注意以下假设基于 0 的数组,显然 Matlab 是基于 1 的.. 例如

0 1 2 3 4 5 6 7 8 
9 A B C D E F G H

假设您知道一行中的列数

row = 12 / 9 ( = 1)
col = 12 % row ( = 3)  % is modulus operator i.e remainder after integer division