create a matrice in a for loop

1 visualizzazione (ultimi 30 giorni)
Miguel Albuquerque
Miguel Albuquerque il 11 Lug 2022
Hey guys, thanks in advance,
I have this moving radar, that detects targets in a specific area, identified by pixels(xtarget,ytarget).
In the end I have this distance_matrix, where rows are the distance to the target(R1-R2-Rd) and the columns are the position of the radar, since this radar is moving.
waypoints are the position of the radar, and it has, 400 positions(1:400 pixels). But the distance_matrix I have, saves the distances in 1 x 400, whic is correct, but if I have more than 1 target in each column(i), this code only saves one distance. I wanted that distance_matrix was a matrix that if column (i) had more that one distance to save, saved all the distances along that column. So imagine i=200, and in i there are 3 distances to save, so in i=200, distance_matrix should be 3x1 , and not 1x1 like I have, can you help me?
for i=1:numel(waypoints) % For each waypoint
Y_transmitter = waypoints(i);
for xx=1:400
for yy=1:400
if AoI(xx,yy) ~= 0 % Target detection
....
if status ==1 & Pt ==1 & Pr ==1 & Wi_Surv ~=0 & Wi_transmit ~=0 % SAR Passive detection
....
R1=sqrt( (X_transmitter-X_target).^2 + (Y_transmitter-Y_target).^2); % Distance transmitter-target in meters
R2=sqrt( (X_receiver-X_target).^2 + (Y_receiver-Y_target).^2); % Distance Receiver-target in meters
Rd=sqrt( (X_receiverref-X_transmitter).^2 + (Y_receiverref-Y_transmitter).^2); % Distance Transmitter-Receiver in meters
distance_matrix(:,i)=R1+R2-Rd;
end
end
end
end
end

Risposte (1)

Harshit Gupta
Harshit Gupta il 12 Lug 2022
Hi, I understand that you want to push more data in column (i) of your distance_matrix.
Try something like this:
distance_matrix(:,i)=[distance_matrix(:,i), new_value]
This will create a vector in each cell of your matrix
Hope this helps!
  5 Commenti
Stephen23
Stephen23 il 12 Lug 2022
distance_matrix=zeros(1,length(waypoints)); % defines a 1xN matrix.
distance_matrix(:,i) % refers to one column of a 1xN matrix, i.e. a 1x1 element.
[distance_matrix(:,i), R1+R2-Rd] % defines a 1x2 matrix.
How do you expect to fit two numbers into the space of one number?
distance_matrix=zeros(2,length(waypoints))
% ^
Miguel Albuquerque
Miguel Albuquerque il 12 Lug 2022
Even if I define the first line as(2, length(waypoints)), it does the same error

Accedi per commentare.

Tag

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by