help with matrix manipulation

12 次查看(过去 30 天)
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

采纳的回答

Walter Roberson
Walter Roberson 2012-4-21

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by