Thread Subject: "Loop stamp" on each value in a "result matrix"

Subject: "Loop stamp" on each value in a "result matrix"

From: Brian Bak

Date: 25 Nov, 2009 14:27:19

Message: 1 of 5

Hi

I have a loop where I at the end of the loop compare a result matrix with the result matrix from the past run of the loop. The matrix is a single column. I replace the values of the old result matrix with the new ones they are larger then the old results.

for i = 1:90
.
.
    results = max(results, results_new)
end

This works fine but i would like to put a stamp on each of the values in the results matrix indicating what value of 'i' this result was obtained. Does anyone know how to do this?

Thanks in advance

Best regards
Brian

Subject: "Loop stamp" on each value in a "result matrix"

From: Jos (10584)

Date: 25 Nov, 2009 15:22:21

Message: 2 of 5

"Brian Bak" <brianlvbak@gmail.com> wrote in message <hejes7$pb1$1@fred.mathworks.com>...
> Hi
>
> I have a loop where I at the end of the loop compare a result matrix with the result matrix from the past run of the loop. The matrix is a single column. I replace the values of the old result matrix with the new ones they are larger then the old results.
>
> for i = 1:90
> .
> .
> results = max(results, results_new)
> end
>
> This works fine but i would like to put a stamp on each of the values in the results matrix indicating what value of 'i' this result was obtained. Does anyone know how to do this?
>
> Thanks in advance
>
> Best regards
> Brian

Can't you take this line out of the loop?

resultsnew = nans(90,1) ; % pre-allocation !
for i=1:90,
  resultsnew(i) = ... % your code filling the i-th entry of the array
end
results = max(resultsnew)

hth
Jos

Subject: "Loop stamp" on each value in a "result matrix"

From: Matt Fig

Date: 25 Nov, 2009 15:49:21

Message: 3 of 5

Would something like this do it?

A = round(rand(3,1));
V = zeros(size(A)); % This holds the loop index where a replacement is made.

for ii = 1:3
Anew = round(rand(3,1)*ii);
diff_A = Anew>A;

if nnz(diff_A)
A(diff) = Anew(diff);
V(ii) = 1;
end
end

Subject: "Loop stamp" on each value in a "result matrix"

From: Brian Bak

Date: 26 Nov, 2009 14:45:19

Message: 4 of 5

Hi MAtt Fig and Jos(10584)

Thank you for your answers.

The restults matrix contains more than 30,000 numbers so the sake of clarity I would like to the final result matrix on a 2 column form with the result value and the loop number value:

result value loop number
1234 2
341 87
145 14
.
.
.

Best regards
Brian

Subject: "Loop stamp" on each value in a "result matrix"

From: Brian Bak

Date: 26 Nov, 2009 16:07:02

Message: 5 of 5

"Brian Bak" <brianlvbak@gmail.com> wrote in message <hejes7$pb1$1@fred.mathworks.com>...
> Hi
>
> I have a loop where I at the end of the loop compare a result matrix with the result matrix from the past run of the loop. The matrix is a single column. I replace the values of the old result matrix with the new ones they are larger then the old results.
>
> for i = 1:90
> .
> .
> results = max(results, results_new)
> end
>
> This works fine but i would like to put a stamp on each of the values in the results matrix indicating what value of 'i' this result was obtained. Does anyone know how to do this?
>
> Thanks in advance
>
> Best regards
> Brian
Hi
I think I have solved it by doing:

for i = 1:90
..
    A = results_new>results(:,1);
    results(:,1) = max(results(:,1), results_new;
    results(:,2) = results(:,2).*(1-A)+ A*i;
end

Then the second column contains the loop number.

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com