help with matrix manipulation

조회 수: 9 (최근 30일)
Evan
Evan 2012년 4월 21일
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일
  댓글 수: 1
Evan
Evan 2012년 4월 21일
Thanks very much for the help

댓글을 달려면 로그인하십시오.

추가 답변 (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