Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
programm error

Subject: programm error

From: Gaurav Verma

Date: 13 Feb, 2012 18:12:11

Message: 1 of 4

Hello sir,
i m doing one program shows some error.
can u help me?

Ie=imread('imd.jpg');
[x,y]=size(Ie);
h=x/2;
for i=1:x
    for j=1:y
    if Ie(i,j)==0
       Ic(i,j)=0;
    else if ((Ie(i+1,j-1)==1)& (Ie(i+1,j+1)==1))
              Ic(i,j)=0;
    else if (((Ie(i+1,j-1)==1)&(i<=h))|(Ie(i+1,j+1)==1) & (i>h))
        Ic(i,j)=1;
    else if (((Ie(i+1,j+1)==1) & i<=h)|| (Ie(i+1,j-1)==1)& (i>h))
            Ic(i,j)=-1;
                end %if
                end %for
        end

Subject: programm error

From: dpb

Date: 13 Feb, 2012 22:07:18

Message: 2 of 4

On 2/13/2012 12:12 PM, Gaurav Verma wrote:
> Hello sir,
> i m doing one program shows some error.
> can u help me?
...

And how are we to know what error that might be if you provide no clues...

--

Subject: programm error

From: Steven_Lord

Date: 13 Feb, 2012 22:14:02

Message: 3 of 4



"Gaurav Verma" <gkumareng@gmail.com> wrote in message
news:jhbjpr$pho$1@newscl01ah.mathworks.com...
> Hello sir,
> i m doing one program shows some error.
> can u help me?
>
> Ie=imread('imd.jpg'); [x,y]=size(Ie);
> h=x/2;
> for i=1:x
> for j=1:y
> if Ie(i,j)==0 Ic(i,j)=0;
> else if ((Ie(i+1,j-1)==1)& (Ie(i+1,j+1)==1))

There's no such thing as the 0th column of a matrix in MATLAB. The first
row/column/element/etc. of an array is row/column/element/etc. 1.

*snip*

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: programm error

From: Roger Stafford

Date: 14 Feb, 2012 15:04:44

Message: 4 of 4

"Gaurav Verma" wrote in message <jhbjpr$pho$1@newscl01ah.mathworks.com>...
> Hello sir,
> i m doing one program shows some error.
> can u help me?
>
> Ie=imread('imd.jpg');
> [x,y]=size(Ie);
> h=x/2;
> for i=1:x
> for j=1:y
> if Ie(i,j)==0
> Ic(i,j)=0;
> else if ((Ie(i+1,j-1)==1)& (Ie(i+1,j+1)==1))
> Ic(i,j)=0;
> else if (((Ie(i+1,j-1)==1)&(i<=h))|(Ie(i+1,j+1)==1) & (i>h))
> Ic(i,j)=1;
> else if (((Ie(i+1,j+1)==1) & i<=h)|| (Ie(i+1,j-1)==1)& (i>h))
> Ic(i,j)=-1;
> end %if
> end %for
> end
- - - - - - - - -
  I see at least two problems here. First, in the for-loops the index j-1 can equal zero and the indices i+1 and j+1 can be above the range of Ic which will produce an error message. Second, the 'elseif' should not have a space between the 'else' and the 'if'. As it stands it does not have enough end's and that will create a parsing error message when the program is compiled.

Roger Stafford

Tags for this Thread

No tags are associated with this thread.

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.

Contact us