Pergunta

I want to check each of the age from a file named "2". This "2" file contains ages and is formatted in the following way:

  • 2010
  • 1997
  • 0
  • ...
  • ...

The code I have written to do this is below, but it returns an error:

enter image description here

data_register = importdata('DATA/2')

for i = 1:700

year=data_register(i);

age=2014-year(i);

B22(A22<=1)=1;
B22(A22>1&A22<50)=-1;
B22(A22>=50)=1; 


D22(i)=B22';

end

feature22= D22'

What am I doing wrong?

Foi útil?

Solução

The reason why is because year is only a single element. When you move to the next iteration, you are traversing out of bounds as year is just a single element but you are trying to access the non-existent second element.

The reason why year is a single element is due to the year = data_register(i) assignment. You need to change the age assignment to the following:

age = 2014 - year;

Aside

Your for loop doesn't make any sense to me. I'm not sure why you are using age when you aren't using it in the statements that follow it. What is A22? B22? Is it related to age? How are these being calculated?

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top