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

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

how to correct subscript indices error in following codes?

Asked by satish thapaliya on 19 Nov 2012
a=0.85;    
  for i=1:7
  filename=strcat('D:\2nd year\EXP season 2\Dry\cat1\',num2str(i),'.bmp');
  I=imread(filename);
  I1=I(:,:,2);
  I2=I(:,:,3);
  G_Channel_cat1(i-2)=mean(mean(I1(293+(-5:5),285+(-5:5))))-mean(mean(I2(293+(-5:5),285+(-5:5))))*a;
  end

0 Comments

satish thapaliya

Products

No products are associated with this question.

1 Answer

Answer by Walter Roberson on 19 Nov 2012
Accepted answer

When i is 1, i-2 is going to be -1, and you cannot store into element number -1 of G_Channel_cat1.

It is not obvious what you are trying to do in that assignment statement, so I cannot suggest any fix other than not subtracting 2 from "i" at that point.

4 Comments

Walter Roberson on 19 Nov 2012

Please show that part of the code, and show the error message.

satish thapaliya on 20 Nov 2012

Here is the code and error message

a=0.85;    
    for i=3:9
    filename=strcat('D:\2nd year\EXP season 2\Dry\cat1\',num2str(i),'.bmp');
    I=imread(filename);
    I1=I(:,:,2);
    I2=I(:,:,3);
    G_Channel_cat1(i-2)=mean(mean(I1(293+(-5:5),285+(-5:5))))-mean(mean(I2(293+(-5:5),285+(-5:5))))*a;
    end
    for i=3:9
    filename=strcat('D:\2nd year\EXP season 2\Dry\cat2\',num2str(i),'.bmp');
    I=imread(filename);
    I1=I(:,:,2);
    I2=I(:,:,3);
    G_channel_cat2(i-2)=mean(mean(I1(301+(-5:5),284+(-5:5))))-mean(mean(I2(301+(-5:5),284+(-5:5))))*a;
    end
    for i=3:9
    filename=strcat('D:\2nd year\EXP season 2\Dry\cat3\',num2str(i),'.bmp');
    I=imread(filename);
    I1=I(:,:,2);
    I2=I(:,:,3);
    G_channel_cat3(i-2)=mean(mean(I1(310+(-5:5),283+(-5:5))))-mean(mean(I2(310+(-5:5),283+(-5:5))))*a;
    end
    for i=3:9
    filename=strcat('D:\2nd year\EXP season 2\Dry\cat4\',num2str(i),'.bmp');
    I=imread(filename);
    I1=I(:,:,2);
    I2=I(:,:,3);
    G_channel_cat4(i-2)=mean(mean(I1(320+(-5:5),285+(-5:5))))-mean(mean(I2(320+(-5:5),285+(-5:5))))*a;
    end
    x=[0.121,0.422,0.844,4.219,12.053,21.094,60.267];
    for i=1:7
        y(i)=(G_channel_cat1(i)+G_channel_cat2(i)+G_channel_cat3(i)+G_channel_cat4(i))/4;
    end
    plot(y,x,'r')

??? Undefined function or method 'G_channel_cat1' for input arguments of type 'double'.

Walter Roberson on 20 Nov 2012

Your first "for" loop assigns to G_Channel_cat1 which has an upper-case C. All your other variables use a lower-case C there.

Walter Roberson

Contact us