array and minimum value and coordinate

1 view (last 30 days)
BARAN Özbakr
BARAN Özbakr on 26 Apr 2014
Commented: dpb on 26 Apr 2014
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 Comment
Azzi Abdelmalek
Azzi Abdelmalek on 26 Apr 2014
This not clear, maybe if you post your code, things will be clear

Sign in to comment.

Answers (1)

dpb
dpb on 26 Apr 2014
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 Comments
BARAN Özbakr
BARAN Özbakr on 26 Apr 2014
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 on 26 Apr 2014
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!