Not sure why I'm getting this error - Index exceeds number of array elements (0).
3 views (last 30 days)
Show older comments
I'm not quite understanding why I am getting this error for the code below. I get the error
Index exceeds the number of array elements (0).
Error in importdata (line 36)
alpha(k,1) = first_data(1);
However I only get this error when the number of files I am trying import exceeds 10. I'm guessing there is something I am missing but I can't quite put my finger on it. Can anyone suggest a way to solve it?
% Read the data from each file
fid = fopen(fullFileName);
c = 0; store = false;
while true
l = fgetl(fid);
if l == -1 % Break loop
break
end
% while ~feof(fid)
% Read Alpha and Beta
if strcmp(l(1:5),'alpha') %Get row starting with alpha
l = fgetl(fid); % get next line
first_data = str2num(l);
%alpha_beta(k,1:2) = first_data([1,3]); % store alpha and beta
alpha(k,1) = first_data(1);
beta(k,2) = first_data(3);
end
% Read matrix of data below 'Dose'
store = strcmp(l(1:4),'Dose');
while store
l = fgetl(fid);
c=c+1;
if l == -1 % Exit and set store back to false
store = false;
break
end
data(c,:) = str2num(l);
end
end
file{k} = data;
clear data
%Read 'Dose', 'SF', 'Errors' into separate cells
dose{k} = file{k}(:,1);
sf{k} = file{k}(:,2);
numcol = @(x) size(x,2);
if numcol(file{k}) == 3
errs{k} = file{k}(:,3)-sf{k};
else
sfanderrs{k} = file{k}(:,3);
errs{k} = file{k}(:,4);
end
end
0 Comments
Answers (1)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!