find minimum over a range of indices

1 Ansicht (letzte 30 Tage)
kamal wisal
kamal wisal am 20 Sep. 2018
Bearbeitet: kamal wisal am 21 Sep. 2018
Dear matlab community i want to calculate indices of min_values of ranges of data in a lengthy array for the following case;
I am modeling a rotating fan blade. i want to detect the blade tip in real time on difrnt positions by lasers installed at outer circumference of the fan. logic is simple: there are (x,y) coords of sensors, and of blade tip (x_tip, y_tip) . when euclidean distance b/w these tip and sensor coords are minimum (happens once every rotation) then they coincide and that time step is the time of arrival (TOA) or detection time for that specific sensor. sample code is:
t_tot=62.5; t_stp=0.5; t_vec=0:t_stp:t_tot; % simulation time (s).
rot=[1:1:7]; % # of rotations
N=18;
rot = reshape(repmat(rot(:).',N,1),1,[])'; %let each rotatn cmplts in 18 t_stps.
[rot_num, rot_indx] = unique(rot,'first'); % indices for each rotation
rot_indx(end+1,1)=find(rot == rot(numel(rot)), 1, 'last'); % index of last value of rotation
N_sens=4; separation=pi/3; % # of sensors to detct blade tip.
theta_sens=pi/3:separation:N_sens*separation; % Sensors' postions
x_sens=L.*cos(theta_sens); y_sens=L.*sin(theta_sens); % (x,y) coords of sensors
theta_inst=linspace(0,rot(end)*2*pi,numel(t_vec))'; %ang_positn of tip @any t_stp
x_tip=L.*cos(theta_inst); y_tip=L.*sin(theta_inst); %tip coords
Eucl_Dist=(((x_tip-x_sens).^2)+(y_tip-y_sens).^2).^0.5; % euclidean distances of
%blade tip from all the sensors over whole simulation time
here Eucl_Dist size is 126(t_stps)*4(sensors). there are 7 rotations in total. so Eucl_dist need to broken into 7 matrices of m*4 size. where m is indices range over which a rotation persists. and index of minimum over each column of each rotation data need to be found. time value of that index is the TOA, so in each rotation at a certain index, TOA(index(rotation(i),:))=time(index(min(Eucld_dist))); TOA size be length(rot)*N_sens, here 126*4. with non-zero values at min(Eucld_dist). I hope i dint make it too confusing. I tried different loop approaches but its not promising. A vectorized approach will be appreciated.

Antworten (1)

KALYAN ACHARJYA
KALYAN ACHARJYA am 20 Sep. 2018
Bearbeitet: KALYAN ACHARJYA am 20 Sep. 2018
As per the title of the question, I have answered here, as mentioned range of the indices
min_data=min(data,[],'all') calculates the minimum over all elements of data.
  1 Kommentar
kamal wisal
kamal wisal am 21 Sep. 2018
Bearbeitet: kamal wisal am 21 Sep. 2018
Thank you for abrupt response @ Kalyan, but i think i could not make myself clear. Let me clarify my question.Please paste the following loop block With the above code i provided and check:
t_vec=t_vec';
TOA=zeros(numel(rot),N_sens);
for i=1:numel(rot_num)
[min_val ind]=min(Eucl_Dist(rot_indx(i):rot_indx(i+1)-1,:),[],1);
if i>1
ind=ind+rot_indx(i); % indx# was calculated only in a range of array
end % and not for whole array.updated here
for j=1:N_sens
TOA(ind(1,j),j)= t_vec(ind(1,j),1); %TOA for every sensor
end
end
I want to vectorize the operation. and get rid of the loop operation.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by