help with matrix manipulation

9 visualizaciones (últimos 30 días)
Evan
Evan el 21 de Abr. de 2012
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

Respuesta aceptada

Walter Roberson
Walter Roberson el 21 de Abr. de 2012
  1 comentario
Evan
Evan el 21 de Abr. de 2012
Thanks very much for the help

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by