Effacer les filtres
Effacer les filtres

optimize my code to work better

1 vue (au cours des 30 derniers jours)
Osita Onyejekwe
Osita Onyejekwe le 22 Nov 2016
Réponse apportée : Hildo le 29 Nov 2016
I have a code that calculates the Euclidean distance between X and Y and selects the minimum coordinate, and once that minimum coordinate is calculated, it removes it from the loop. My problem is that after the first step, what happens if the coordinate that's removed is not successive but before the first point? Basically I want to re-write this code so that it relies only on the coordinate of interest and not the index. I don't want to store the index anymore. Any help will be appreciate. Thank you
X = Observed_Signal_Positive_Inflection_Points_Coordinates;
Y = Positive_Inflection_Points_Coordinates_denoised;
X
Edited_Array = Y; % this will take care of the changing array size
nX = size(X,1);
Index = zeros(1, nX);
for k = 1:nX
ED = pdist2(X(k,:),Edited_Array,'euclidean');
ED = ED'
[Minimial_Euclidean_Distance, Index(k)] = min(ED(:,1), [], 1);
Minimial_Euclidean_Distance
Index(k) = Index(k) + (k-1)
Minimal_Positive_INFLP_ED(k,:)= [X(k,:), Y(Index(k),:), min(ED(:,1))];
Edited_Array(Index(k)-(k-1),:) = [];
end

Réponses (1)

Hildo
Hildo le 29 Nov 2016
First of all, avoid don't close the lines. Usually you don't want to print the results of each line, so use ";" at the end of each line and print your results after the loop.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by