Create an array of numbers

5 ビュー (過去 30 日間)
Miguel Albuquerque
Miguel Albuquerque 2022 年 7 月 16 日
編集済み: dpb 2022 年 7 月 16 日
hey guys, thanks in advance
I have this matrix attached , distance_matrix. Basically is the position of a plane along a linear direction.
I have this code that finds the minimum value, which means distance to a target according to the specific position of the plane.
What I want to do , is assume that R0 is the origin of the plane movement( column 184). But we can see that plane has more positions, column 185,186,etc... I want to create an array of positions, where R0 is the center( perhaps x=0), and as the example in the matrix 185(x=1), 186(x=2),... 190(x=6). The inf numbers in the matrix doesn´t matter, but I still need that positions occupied.
But I also want that the code could assume that if R0= 190, then columns 184(x=-6), 185(x=-5),... 191(x=1),...
R0=min(distance_matrix(distance_matrix ~= 0));

回答 (1 件)

dpb
dpb 2022 年 7 月 16 日
[R0,ixR0]=min(distance_matrix(distance_matrix ~= 0));
x=(1:numel(distance_matrix))-ixR0;
  2 件のコメント
Miguel Albuquerque
Miguel Albuquerque 2022 年 7 月 16 日
I have done this code:
I think its correct, your code says ixR0 is 1, when it is 184
[rows,columns]=size(distance_matrix);
distance_matrix(distance_matrix==0) = NaN ;
[val,idx] = min(distance_matrix);
for col = 1 : columns
thisColumn = distance_matrix(:, col);
idx2=col-idx;
tshift(:,col)=(idx2.^2)./ (val.*c);
end
dpb
dpb 2022 年 7 月 16 日
編集済み: dpb 2022 年 7 月 16 日
Not what I get with the data file you attached --
>> [R0,idx]=min(distance_matrix(distance_matrix ~= 0))
R0 =
84.9718
idx =
184
>>
Looks right to me...dunno how you got something different -- the 1 value would indicate you somehow applied to a subset of the data from that point on.
Of course, you get same result from...
>> [R0,idx]=min(distance_matrix)
R0 =
84.9718
idx =
184
>>

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by