MATLAB: Index exceeds matrix dimensions

arraydimensionexportindex

Hi. I am trying to export some data to a database and I am getting following error message
Index exceeds matrix dimensions.
Error in data2postgresql (line 135)
exportData = {data{k,4}, data{k,2}, data{k,1},
data{k,6}, data{k,7}};
for this code
%%Export data to the database
switch databaseExport
case 0 % no database export
case 1 % export to database
for k = 1:nRows
% sort the imported data and move it into exportData
exportData = {data{k,4}, data{k,2}, data{k,1}, data{k,6}, data{k,7}};
% insert data to the appropriate table and columns of the database
colNames = {'"A"', '"B"', '"C"', '"D"', '"E"'};
fastinsert(conn, exportTable, colNames, exportData);
end
otherwise % no export
end
Some info: nRows is the length of data{:,1} and data is a 1×7 2074487 Bytes cell and exportData is a 1×5 691766 Bytes cell with following entries for k=1, I guess, '001' / 1 / 86399×1 double / [] / []
Do you have any idea why I get a wrong dimension error and how I could fix it? Thank you very much for your help. Best regards

Best Answer

Well, either data has less than 7 columns or less than nRows rows.
Before the for loop insert these two lines:
assert(nRows <= size(data, 1), 'data has less than nRows rows');
assert(size(data, 2) >= 7, 'data has less than 7 columns');
or put a breakpoint on the exportData line and check the size of data manually.