Index in position 1 exceeds array bounds (must not exceed 1).

5 visualizaciones (últimos 30 días)
Anisha Menro
Anisha Menro el 30 de Jun. de 2020
Comentada: Voss el 30 de Jun. de 2020
I have been trying to run this function into another function and then both the functions in the main script. But sometimes it gives error that some unknown variables and sometimes this 'Index in position 1 exceeds array bounds (must not exceed 1)'. Can anyone please help? Here is the code which is giving Indexing error in Line27:
function [NodeMat] = Function_Sofistik_ReadNodes (FileName, NodeIDstr)
% clear all; close all; clc
% FileName = ['MainModel' '_NODES_' '.lst']; % Sofistik .lst file name
% NodeIDstr = 'DATA EXTRACTION: NODE DATA'; % Header to search in Sofistik nodes output file
addpath functions ;
addpath SofistikFiles ;
% Read node coordinates output file and save data
fid = fopen (FileName, 'r' );
countRN = 1;
while 1
tline = fgetl (fid);
if ~ ischar (tline)
break ;
end
NodeFileData {countRN, 1} = tline;
if (isempty (NodeFileData {countRN, 1})) ~ = 1
break ;
NodeLineNo = countRN;
end
countRN = countRN + 1;
end
fclose (fid);
% Save nodes
countSN = 1;
NodeLineNo = countSN;
while isnumeric (str2num (NodeFileData {NodeLineNo + countSN + 1,1})) && isempty (str2numNodeFileData {NodeLineNo + countSN + 1,1})) == 1
TempNode = str2num (NodeFileData {NodeLineNo + countSN + 1,1});
if length (TempNode) == 4 && TempNode (1) ~ = 0
NodeMat (countSN,:) = str2num (NodeFileData {NodeLineNo + countSN + 1 ,:});
end
countSN = countSN + 1;
end
  1 comentario
Voss
Voss el 30 de Jun. de 2020
Note that when line 27 is run the first time, NodeLineNo has value 1 and countSN has value 1, so the code is checking NodeFileData{3,1}. Is this the intended behavior? If not, this may be the cause of the 'index in position 1 ...' error.
Also note that (also on line 27) str2numNodeFileData is a typo. Should be str2num(NodeFileData{...}). This may be the cause of the 'unknown variable' error.
If making changes based on these considerations doesn't produce the desired result, it will be helpful for us to see an example input file or at least a description of what you expect the code to do.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Language Fundamentals en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by