From: mat001 on
I have a 2d matrix and i want to set something like that

if any element of matrix will be greater than maximum value (let say 50) then error

how to do that

Please reply me soon.

Regards
From: Sean on
"mat001 " <priya.biomath(a)yahoo.co.in> wrote in message <i4392l$2is$1(a)fred.mathworks.com>...
> I have a 2d matrix and i want to set something like that
>
> if any element of matrix will be greater than maximum value (let say 50) then error
>
> how to do that
>
> Please reply me soon.
>
> Regards

if(any(matrix>50))
error('Ha!');
end
From: Walter Roberson on
Sean wrote:
> "mat001 " <priya.biomath(a)yahoo.co.in> wrote in message
> <i4392l$2is$1(a)fred.mathworks.com>...
>> I have a 2d matrix and i want to set something like that
>>
>> if any element of matrix will be greater than maximum value (let say
>> 50) then error
>>
>> how to do that
>>
>> Please reply me soon.
>>
>> Regards
>
> if(any(matrix>50))
> error('Ha!');
> end

Sean, the original poster indicated that it was a 2D matrix.
matrix > 50 would result in a 2D matrix of logical values
any() applied to that would result in a row vector of logical values
"if" applied to that would be the same as "if all(...)" and so would
test if *all* of the columns had at least one value greater than 50.

The easiest fix to this is

if any(matrix(:)>50))
From: Sean on
Walter Roberson <roberson(a)hushmail.com> wrote in message <UFb9o.59107$dx7.43323(a)newsfe21.iad>...
> Sean wrote:
> > "mat001 " <priya.biomath(a)yahoo.co.in> wrote in message
> > <i4392l$2is$1(a)fred.mathworks.com>...
> >> I have a 2d matrix and i want to set something like that
> >>
> >> if any element of matrix will be greater than maximum value (let say
> >> 50) then error
> >>
> >> how to do that
> >>
> >> Please reply me soon.
> >>
> >> Regards
> >
> > if(any(matrix>50))
> > error('Ha!');
> > end
>
> Sean, the original poster indicated that it was a 2D matrix.
> matrix > 50 would result in a 2D matrix of logical values
> any() applied to that would result in a row vector of logical values
> "if" applied to that would be the same as "if all(...)" and so would
> test if *all* of the columns had at least one value greater than 50.
>
> The easiest fix to this is
>
> if any(matrix(:)>50))

That is correct, sorry.