MATLAB MATRIX需要的指导

时间:2017-11-15 08:08:43

标签: matlab search matrix

我正在编写一个脚本,它接受数组值并生成一个矩阵,如代码所示。基于以下代码,我想要做的是,我想搜索给定值的另一个矩阵,并找到与程序中定义的celflr变量对应的值,并创建一个新的行到矩阵。

这是当前的输出:

C =

   63.6944   51.7205  -38.2795  -39.0000  -38.0000   B value correspond to -39
  107.5034   68.4665  -21.5335  -22.0000  -21.0000   B value correspond to -22
  155.1031   75.2618  -14.7382  -15.0000  -14.0000   B value correspond to -15
  203.8553   78.8393  -11.1607  -12.0000  -11.0000
  253.0948   81.0307   -8.9693   -9.0000   -8.0000
  302.5838   82.5070   -7.4930   -8.0000   -7.0000
  352.2172   83.5677   -6.4323   -7.0000   -6.0000
  401.9415   84.3662   -5.6338   -6.0000   -5.0000

以上我想要添加另一个列,该列正在搜索给定矩阵中的相应值,例如-39-22-1512-9-8-7-6将在2D矩阵中搜索,如下所示B。现在我想在下面的矩阵中显示另一列,它显示B中矩阵A的相应值。

B = [-39   14
     -38   12
     -15   10
     -12   17
     -9    45
     -8    16]

a = 1;
for X = [50 100 150 200 250 300 350 400]

   R = hypot(41.4586-2, X);
   theta = atand(X/(41.4586-2));

   dep = theta-90;
   flr = floor(dep);
   Y(row1:col1) = find(Y==flr);
   dB1 = Y(row1:2);

   cel = ceil(dep);
   Y(row2,col2) = find(Y==cel);
   dB2= Y(row2:2);

   A(1,a) = R;
   A(2,a) = theta;
   A(3,a) = dep;
   A(4,a) = flr;
   A(5,a) = cel;
   A(6,a) = dB1;

   a = a+1;

end

C = transpose(A);

1 个答案:

答案 0 :(得分:0)

C =

   63.6944   51.7205  -38.2795  -39.0000  -38.0000   14-> value of B in col 2
  107.5034   68.4665  -21.5335  -22.0000  -21.0000   12
  155.1031   75.2618  -14.7382  -15.0000  -14.0000   10
  203.8553   78.8393  -11.1607  -12.0000  -11.0000   17
  253.0948   81.0307   -8.9693   -9.0000   -8.0000   45
  302.5838   82.5070   -7.4930   -8.0000   -7.0000   16 

this should be the output