Index exceeds matrix dimensions

4 Ansichten (letzte 30 Tage)
GuidingDrifter
GuidingDrifter am 22 Okt. 2015
Bearbeitet: GuidingDrifter am 23 Nov. 2015
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

Akzeptierte Antwort

Guillaume
Guillaume am 22 Okt. 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');
or put a breakpoint on the exportData line and check the size of data manually.
  5 Kommentare
Guillaume
Guillaume am 22 Okt. 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
GuidingDrifter
GuidingDrifter am 22 Okt. 2015
Bearbeitet: GuidingDrifter am 23 Nov. 2015
Thanks! Merci beaucoup! Yes, numel is what I was looking for. I do have a lot of entries now.
The first element of the container is the only one that has 80000+ rows. The other elements consist of just 1 row.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by