필터 지우기
필터 지우기

Create an array of numbers

조회 수: 1 (최근 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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by