Filter löschen
Filter löschen

Create an array of numbers

1 Ansicht (letzte 30 Tage)
Miguel Albuquerque
Miguel Albuquerque am 16 Jul. 2022
Bearbeitet: dpb am 16 Jul. 2022
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));

Antworten (1)

dpb
dpb am 16 Jul. 2022
[R0,ixR0]=min(distance_matrix(distance_matrix ~= 0));
x=(1:numel(distance_matrix))-ixR0;
  2 Kommentare
Miguel Albuquerque
Miguel Albuquerque am 16 Jul. 2022
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 am 16 Jul. 2022
Bearbeitet: dpb am 16 Jul. 2022
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
>>

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by