用nan元素在matlab中重塑矩阵

用nan元素在matlab中重塑矩阵,matlab,matrix,Matlab,Matrix,我在matlab中有一个Nx3-矩阵,在第一列中有一个从0到360的度值,在第二列中有一个从0到0.5的半径值,在第三列中有一个整数。(M(n,1),M(n,2))的每一个组合都是唯一的,矩阵是M,而n是介于1和n之间的随机数,但是M(:,1)或M(:,2)中有一个值可能不止一次M排序,首先在第一行之后,然后在第二行之后 我现在的目标是将这个矩阵重塑成一个360xV-矩阵,在M(:,2)中使用V唯一值的数量。如果在M(o,1)和M(p,2)位置M(:,3)中有一个值,则1 有没有一种简单的方法可

我在matlab中有一个
Nx3
-矩阵,在第一列中有一个从0到360的度值,在第二列中有一个从0到0.5的半径值,在第三列中有一个整数。
(M(n,1),M(n,2))
的每一个组合都是唯一的,矩阵是
M
,而
n
是介于1和n之间的随机数,但是
M(:,1)
M(:,2)
中有一个值可能不止一次
M
排序,首先在第一行之后,然后在第二行之后

我现在的目标是将这个矩阵重塑成一个
360xV
-矩阵,在
M(:,2)
中使用
V
唯一值的数量。如果在
M(o,1)
M(p,2)
位置
M(:,3)
中有一个值,则
1
有没有一种简单的方法可以做到这一点,或者我必须为此编写自己的函数


您需要编写一个方法,因为您所描述的内容完全针对您的问题。有一些方法可以找到唯一的值,因此这将有助于您为
循环设计

您可以使用一种方法,为输入数组中的
第一列
第二列
找到
唯一索引
,然后使用这些索引以适当的方式设置元素(在代码中作为注释进行了更详细的讨论)使用
第三列的元素调整输出数组的大小-

%// Input array
A = [
    0 0.25 1
    0 0.43 4
    1 0.25 2
    2 0.03 5
    2 0.43 2 ]

%// Find unique indices for col-1,2
[~,~,idx1] = unique(A(:,1)) %// these would form the row indices of output
[~,~,idx2] = unique(A(:,2)) %// these would form the col indices of output

%// Decide the size of output array based on the "extents" of those indices
nrows = max(idx1)
ncols = max(idx2)

%// Initialize output array with NaNs
out = NaN(nrows,ncols)

%// Set the elements in output indexed by those indices to values from
%// col-3 of input array
out((idx2-1)*nrows + idx1) = A(:,3)
代码运行-

out =
   NaN     1     4
   NaN     2   NaN
     5   NaN     2

发布一个带有输入和所需信息的小示例output@LuisMendo:完成了,我希望这会让事情变得容易一点。
%// Input array
A = [
    0 0.25 1
    0 0.43 4
    1 0.25 2
    2 0.03 5
    2 0.43 2 ]

%// Find unique indices for col-1,2
[~,~,idx1] = unique(A(:,1)) %// these would form the row indices of output
[~,~,idx2] = unique(A(:,2)) %// these would form the col indices of output

%// Decide the size of output array based on the "extents" of those indices
nrows = max(idx1)
ncols = max(idx2)

%// Initialize output array with NaNs
out = NaN(nrows,ncols)

%// Set the elements in output indexed by those indices to values from
%// col-3 of input array
out((idx2-1)*nrows + idx1) = A(:,3)
out =
   NaN     1     4
   NaN     2   NaN
     5   NaN     2