array and minimum value and coordinate

Hi, everyone, first I want to explain my code.
that is, I am doing some iteration but iteration is done according to some criteria. I have 5 criteria and each criteria there some iterations. Program starts, criteria is selected then iterations is done. But after each iteration, error is calculated according referance value. So that I want to put all error in array and find their minimum. But I also have to know that minumin error belongs which criteria and which iteration.
can u help me about this ?
king regards

댓글 수: 1

This not clear, maybe if you post your code, things will be clear

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

답변 (1개)

dpb
dpb 2014년 4월 26일

0 개 추천

Basically, preallocate an array of the size of number of criterion (5) by the number of pieces of data you want to keep (in your description I see
  • the iteration number/identifier
  • the error for the particular criterion
So,
errarray=zeros(5,2); % allocate room
index=0; % an index variable for which we're on...
%do iteration one here...
index=index+1;
errarray(index,1)=iteration; % save the iteration value
errarray(index,2)=result-refvalue; % and the error
%do iteration two here...
index=index+1;
errarray(index,1)=iteration; % save the iteration value
errarray(index,2)=abs(result-refvalue); % and the error
% lather, rinse, repeat...
When done w/ all five, then
errarray=sortrows(errarray,2); % sort by error column
error=errarray(1,:); % the first row is the minimum and the aux value with it
You can also use
[emin,idx]=min(errarray(:,1)); % find the minimum and location thereof
error=errarray(idx,:); % idx is the row of the minimum
If your repeat is a loop or a nest of multiple loops, just rearrange the linear path above within that structure.

댓글 수: 2

BARAN Özbakr
BARAN Özbakr 2014년 4월 26일
thanks for answer, but the problem is that for example; criteria5 have 3 iteration but criteria1 has only 1. What can I do in this situation ?
dpb
dpb 2014년 4월 26일
Add enough dimensions to account for the number of variables need or use cell arrays to hold different numbers of items per cell.
Need a better outline of the actual code as Azzi notes to do more than generic answers as given.

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

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2014년 4월 26일

댓글:

dpb
2014년 4월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by