Borrar filtros
Borrar filtros

Create an array of numbers

1 visualización (últimos 30 días)
Miguel Albuquerque
Miguel Albuquerque el 16 de Jul. de 2022
Editada: dpb el 16 de Jul. de 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));

Respuestas (1)

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

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by