Index exceeds matrix dimensions Economic Model

Hello everybody, I have a question. Perhaps any of you could be kind enough to help me. It has to do with the firing part of my model:
  • f=randperm(length(workforce));
  • f=f(1:-vacancies(i));
Now normally what happens you get something like this: (when there are 2 vacancies for i(the firm)):
  • f=[3,2,3,4,12];
  • f=f(1:--2)
And it returns: [3,2], so that these are both fired. However I am adjusting the model and now I have a situation where it’s possible that: (still when there are 2 vacancies)
  • f=[3];
  • f=f(1:--2)
And it doesn’t work, because there aren’t 2 to fire. Therefore I get an error: Index exceeds matrix dimensions. Instead I would like the model to fire the one and leave the other vacancy unfulfilled. I have been wrapping my head around this and would appreciate any suggestions!
Thanks in advance!

 Akzeptierte Antwort

Cam Salzberger
Cam Salzberger am 18 Mai 2017

0 Stimmen

Hello Erdtsieck,
Probably the easiest solution is to simply ensure the final index doesn't go beyond the max length of the array:
f=f(1:min(-vacancies(i),numel(f)));
-Cam

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by