MATLAB Answers

I am stuck with inserting data into my MS Access Database. I already converted the data into cell array but it still returns me the error indicating that I am inputting the wrong data type.

조회 수: 4(최근 30일)
Tan Jun Hao
Tan Jun Hao 20 May 2015
댓글: Tan Jun Hao 21 May 2015
C =
'SGX 8873 K'
>> iscell(C)
ans =
1
>> datainsert(conn,'VehicleLocation','col2','C')
Error using database/datainsert (line 58)
Input data must be a cell array or numeric matrix.
Been stuck on inserting the data into the database for quite some time now. The input data 'C' is already verified as cell array by the command iscell(C). Anybody got any idea what am I doing wrongly? Thanks.

  댓글 수: 3

Umakant
Umakant 20 May 2015
Can you tell me which release of MATLAB you are using? From the definition of variable 'C' given above, it looks like 'C' is of class 'char' and not a cell.
Walter Roberson
Walter Roberson 20 May 2015
Umakant, examine the below:
>> 'ABC'
ans =
ABC
>> {'ABC'}
ans =
'ABC'
When you see a string with quotes around it and indented, that is indicating a cell array containing the string; if it were a plain string then it would be displayed without the quote marks or indentation.
Tan Jun Hao
Tan Jun Hao 20 May 2015
Umakant, I am currently using r2015a.
I have attached a photo of the variable editor, which shows that C is a 1x1 cell.

로그인 to comment.

답변(3개)

the cyclist
the cyclist 20 May 2015
편집: the cyclist 20 May 2015
Guessing you want to remove the quotes from around C in the datainsert statement. You are trying to insert the single character 'C', rather than your variable C.

  댓글 수: 1

Tan Jun Hao
Tan Jun Hao 20 May 2015
C =
'SGX 8873 K'
>> iscell(C)
ans =
1
>> datainsert(conn,'VehicleLocation','col2',C)
Cell contents reference from a non-cell array object.
Error in database/datainsert (line 72)
insertField = [ insertField fieldNames{i}]; %#ok
Thanks for the prompt reply. However, MATLAB still indicates that I am not inputting a cell array data. Any idea how to solve this problem?

로그인 to comment.


Walter Roberson
Walter Roberson 20 May 2015
datainsert(conn,'VehicleLocation', {'col2'}, C)
The column names must be cell array of string.

  댓글 수: 2

Tan Jun Hao
Tan Jun Hao 20 May 2015
datainsert(conn,'VehicleLocation',{'col2'},C)
Error using database/datainsert (line 106) [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
Tried doing it before but couldn't work.
Walter Roberson
Walter Roberson 20 May 2015
Sorry, I do not have that toolbox, so I cannot check the code to see what is happening.

로그인 to comment.


Thomas Koelen
Thomas Koelen 20 May 2015
Are you sure you already created a database?

  댓글 수: 5

표시 이전 댓글 수: 2
Tan Jun Hao
Tan Jun Hao 20 May 2015
I added VehicleLocation already. You can see it in the PNG image I attached. It's at the left hand side of the screen.
Walter Roberson
Walter Roberson 20 May 2015
You do not have a column named 'col2', you have a column named 'LicensePlate'
Tan Jun Hao
Tan Jun Hao 21 May 2015
Alright thanks! That solved my problem. But now I am currently stuck at inserting multiple columns of data in one instance. Any ideas?

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.


Translated by