Index exceeds matrix dimensions
1 view (last 30 days)
Show older comments
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 1x7 2074487 Bytes cell and exportData is a 1x5 691766 Bytes cell with following entries for k=1, I guess, '001' / 1 / 86399x1 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
0 Comments
Accepted Answer
Guillaume
on 22 Oct 2015
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');
5 Comments
Guillaume
on 22 Oct 2015
Ok, the cell array, the container has only one row and 7 columns. The 1st element of the container, a double vector, has only 1 column but 86399 rows. What about the other 6 elements of data. Have they all got 86399 rows?
What is it you're trying to put in exportdata?
Maybe what you meant to do was:
for k = 1:numel(data{1})
exportdata = {data{1}(k), data{2}(k), data{3}(k), data{4}(k), data{5}(k), data{6}(k), data{7}(k)};
%...
end
More Answers (0)
See Also
Categories
Find more on Matrix Indexing 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!