- length() is fragile: It uses to longer dimension. You cannot be sure if your table has more rows than columns. Use height() instead or size(data, 1) in older Matlab versions.
- readtable has 1 output only So what do you expect text to be?
- Your code replies the value of i as age, but the value of i comes from the last iteration of the loop: