please help, I want to make comparative loop

Hi everyone, I have 2 problems.
1-I want to plot a figure for each value of y its mean i should have 10 figures, i tried many cases but i only got 1 figure.
2- i want to get max(y) for each iteration. then max y for all iteration and i want to know the max y belong to which step.
M = eye(2,2);
C = [ 2 3; 1 5];
t = 1:1:10
for i = 1:1:10
y = M * C
plot (t, y)
y1 = max(y)
y2 = max(y1(1,:)) % scalar
end
y3 = max(y2) % this is the max among all values of y for all steps
% for y3 i want to know its belong to which row in y2 ?
Thanks for your help, your help always appreciated

 Respuesta aceptada

Walter Roberson
Walter Roberson el 24 de Mayo de 2013
1) Before your plot() call, insert
figure();
2)
In the loop,
y2(i) = max(y1(1,:));
After the loop,
[y3, y3row] = max(y2);

6 comentarios

Brwa
Brwa el 25 de Mayo de 2013
Can i control the number of figures?
I mean for above example i have 10 figures, but Im more interested in the figure which include max value. in other word i want to plot y number y3row only.
Walter Roberson
Walter Roberson el 25 de Mayo de 2013
Why are you using a loop? Nothing in your loop depends on "i" and you are not altering any of the variables that are used as the data source, so every iteration of the loop would be the same.
Brwa
Brwa el 25 de Mayo de 2013
The purpose for using loop because variable C is consist of several matrices and variable A is only one matrix so, i use loop to add all C matrices (one by one) with A matrix.
each time add them i want to get a figure but sometimes i just want to get a figure for one of them.
I hope you give me some good idea
Thanks
Image Analyst
Image Analyst el 25 de Mayo de 2013
But you're not changing C inside the loop - it's the same every single iteration.
Brwa
Brwa el 25 de Mayo de 2013
so, how can i change it ? Sorry Im new in matlab.
in the example i just right down one matrix for C but actually i got C from another loop so its more than one matrix. does this program always use one of C matrices or each time will change C?
Image Analyst
Image Analyst el 29 de Mayo de 2013
The way you wrote the code, there is only one C so it will use only that one C.

Iniciar sesión para comentar.

Más respuestas (1)

Brwa
Brwa el 24 de Mayo de 2013
Thank you Mr Walter Roberson, both of them works well.
thanks alot, wish you the best

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Preguntada:

el 24 de Mayo de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by