How to solve the error "Index in position 2 exceeds array bounds."
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Rita Akonobi
el 18 de Mzo. de 2020
Comentada: Rita Akonobi
el 19 de Mzo. de 2020
Hi, I'm running a code and I keep getting this error
'Index in position 2 exceeds array bounds'
How do i fix it please, The corona virus has really restricted my movement
2 comentarios
Walter Roberson
el 19 de Mzo. de 2020
We would need to see your code. If it reads in files, we would need the files as well.
Rita Akonobi
el 19 de Mzo. de 2020
Editada: Ameer Hamza
el 19 de Mzo. de 2020
Respuesta aceptada
Ameer Hamza
el 19 de Mzo. de 2020
Editada: Ameer Hamza
el 19 de Mzo. de 2020
It turns out that the error is caused by wrong field names in the function truss2D_readdata. Some field names in the text file are a bit different as compared to the function. Change the line
matprop.yield = fscanf(fid, '\nYIELD_STRESS = %f', 1);
to
matprop.yield = fscanf(fid, '\nYIELD STRESS = %f', 1);
and change the line
npload = fscanf(fid,'\nPOINT_LOADS = %d',1);
to
npload = fscanf(fid,'\nNODES_WITH_POINT_LOAD = %d',1);
3 comentarios
Ameer Hamza
el 19 de Mzo. de 2020
Editada: Ameer Hamza
el 19 de Mzo. de 2020
Glad to be of help. I would also take this opportunity to point to this resource on debugging the MATLAB program: https://www.mathworks.com/help/matlab/matlab_prog/debugging-process-and-features.html. The error message indicates the line at which the error occurred. Just add a breakpoint at that line and see what might be causing the issue. Most of the time, the problem is caused by a trivial mistake.
Más respuestas (0)
Ver también
Categorías
Más información sobre Biotech and Pharmaceutical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!