help with matrix manipulation
12 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello all,
I currently have two matrices, called rangetruncate and afmagtruncate, with the nth row of each representing a series of x and y coordinates. As the matrix rangetruncate has multiple values in each row that are the same I wish to add together the corresponding afmagtruncate values and average, leaving each row in the afmagfinal matrix corresponding to a single vector of x coordinates called finalrange. The rangetruncate matrix has been previously rounded to 2 dp. The code i have written however seems to skip out iterations every now and again and i cant figure out why.
[e f] = size(rangetruncate);
rangefinal = 0:0.01:10000;
afmagfinal = zeros(e,numel(rangefinal));
% create loop for each row then parse for each value of rangefinal
for i = 1:e
for j = 1:numel(rangefinal)
thisrange = rangefinal(j);
total = 0;
count = 0;
for k = 1:f
if thisrange == rangetruncate(i,k);
% sum of y values
total = total + afmagtruncate(i,k);
% increment number of occurrences
count = count + 1;
end
end
% perform average and store in afmagfinal
afmagfinal(i,j) = total/count;
end
end
I would be very grateful if you could offer any suggestions as to what could be the cause or an easier way of doing it. Many thanks
0 commentaires
Réponse acceptée
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!