-2

How do I find minimum for the first loop? ii is the minimum value for each iteration while running jj. I want the local minimum and global minimum values.

How could I use vectorization to make the same above operation work?

clear all, clc

p = 1;
for ii=1:5
    q = 1;
    for jj = 0.1:0.1:0.5

        x1 = 2*jj;
        x  = x1+ii;

        X1(p) = x;

        X2 = min(X1);         
        y  = min(X2);

        p = p+1;
        q = q+1;
    end
end
Rody Oldenhuis
  • 37,726
  • 7
  • 50
  • 96
  • 2
    It is best [not to use `i` and `j` as variable names in Matlab](http://stackoverflow.com/questions/14790740/using-i-and-j-as-variables-in-matlab). – Shai Oct 02 '13 at 06:16
  • Also, you don't need to enclose variables with brackets (`[]`). Use them only for creating/concatenating arrays. – Eitan T Oct 02 '13 at 07:56
  • It is unclear what you are actually looking for (e.g. the minimum of which value). – Tim Oct 02 '13 at 09:16
  • 3
    You find the minimum by *thought*: the minimum is 1.2 (`ii==1` and `jj==0.1` gives `x=1.2`). – Rody Oldenhuis Oct 02 '13 at 15:06

1 Answers1

0

Rody Oldenhuis is right, it is not dynamic, so no reason for a computation..

but some comments:

Replace

for jj = 0.1:0.1:0.5
    x1 = 2*jj; 

with

for x1 = 0.2:0.2:1

you ment?

X2(q) = min(X1); 

using less indices makes the code more readable aswell.

as for skipping all the looping, this should help you on your way

(1:n)' * ones(1,n)
min(Matrix,dim)
help min
Filou
  • 521
  • 2
  • 7