Prev: HSV Quantization
Next: PRINTDLG(GCF) error
From: Erik L on 14 Jun 2010 06:18 I have a matrix A=[0 2 3 4 3 1 0] I want to check each element of A in if condition: if ANY element is greater than or equal to 2, my condition is false. I don't want to use the following code: If(A(1,1)<2 && A(1,2)<2 && A(1,3)<2 && A(1,4)<2......... ...... Is there any alternative, because i have a very huge row vector. thanks Erik
From: Wayne King on 14 Jun 2010 06:28 "Erik L" <lookgrn(a)gmail.com> wrote in message <hv4vks$ogs$1(a)fred.mathworks.com>... > I have a matrix A=[0 2 3 4 3 1 0] > > I want to check each element of A in if condition: > > if ANY element is greater than or equal to 2, my condition is false. > > I don't want to use the following code: > > If(A(1,1)<2 && A(1,2)<2 && A(1,3)<2 && A(1,4)<2......... > > ..... > > > Is there any alternative, because i have a very huge row vector. > > thanks > > Erik Hi Erik, A = [0 2 3 4 3 1 0]; if (any(A>2)) disp('There is an element greater than 2.'); else disp('No element is greater than 2'); end Wayne
From: Erik L on 14 Jun 2010 06:37 "Wayne King" <wmkingty(a)gmail.com> wrote in message <hv507r$1pa$1(a)fred.mathworks.com>... > "Erik L" <lookgrn(a)gmail.com> wrote in message <hv4vks$ogs$1(a)fred.mathworks.com>... > > I have a matrix A=[0 2 3 4 3 1 0] > > > > I want to check each element of A in if condition: > > > > if ANY element is greater than or equal to 2, my condition is false. > > > > I don't want to use the following code: > > > > If(A(1,1)<2 && A(1,2)<2 && A(1,3)<2 && A(1,4)<2......... > > > > ..... > > > > > > Is there any alternative, because i have a very huge row vector. > > > > thanks > > > > Erik > > Hi Erik, > > A = [0 2 3 4 3 1 0]; > if (any(A>2)) > disp('There is an element greater than 2.'); > else > disp('No element is greater than 2'); > end > > > Wayne Thanks Wayne If my condition is if all elements are <2, what will be the exact code. Cheers Erik
From: Erik L on 14 Jun 2010 06:39 "Wayne King" <wmkingty(a)gmail.com> wrote in message <hv507r$1pa$1(a)fred.mathworks.com>... > "Erik L" <lookgrn(a)gmail.com> wrote in message <hv4vks$ogs$1(a)fred.mathworks.com>... > > I have a matrix A=[0 2 3 4 3 1 0] > > > > I want to check each element of A in if condition: > > > > if ANY element is greater than or equal to 2, my condition is false. > > > > I don't want to use the following code: > > > > If(A(1,1)<2 && A(1,2)<2 && A(1,3)<2 && A(1,4)<2......... > > > > ..... > > > > > > Is there any alternative, because i have a very huge row vector. > > > > thanks > > > > Erik > > Hi Erik, > > A = [0 2 3 4 3 1 0]; > if (any(A>2)) > disp('There is an element greater than 2.'); > else > disp('No element is greater than 2'); > end > > > Wayne if(all(A<2) thanks Wayne, i got it. cheers
|
Pages: 1 Prev: HSV Quantization Next: PRINTDLG(GCF) error |