0

gdp_p_h and p are vectors. But for some reason this doesn't want to work. I keep getting an error saying: "A(I) = X: X must have the same size as I"

for entry = gdp_p_h
      function_array(end + 1) = polyval(p,entry)
end;
2
  • 1
    what about function_array(end+1,:) ? Commented Apr 28, 2015 at 9:39
  • Do not forget to accept the answer then, so it is useful for future "lost programmers"! :) Commented May 1, 2015 at 14:08

1 Answer 1

2

When using polyval, if entry is an array it will return something the same size.

In your case you are using the loop pretty badly, so entry will be a whole array and function_array(end+1) is only a single number, so it can not store an array.

2 options:

If you want to keep the loop (if you have more things inside), write it properly!

I am guessing that you want:

for ii=1:length(gdp_p_h)
     entry=gdp_p_h(ii);
     function_array(end + 1) = polyval(p,entry);
end

Else, if that's the only thing you are doing inside the loop, you just dont need it.

function_array=polyval(p,gdp_p_h);

will do the job.


Learn how to write for loops here: http://uk.mathworks.com/help/matlab/ref/for.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.