0

I am using matlab 2009 version. I am acessing data through database using following code

    conn = actxserver('ADODB.Connection');
    conn.Open('Provider=sqloledb;Data Source=localhost\SQLEXPRESS;Initial Catalog=user_control_ex01;Integrated Security=SSPI;');
    dat=conn.Execute('select * from user_ident').GetRows;

the table returned is in this format

dat = 

[         1]    [         2]    [         3]    [         4]
'Admin     '    'user      '    'user2     '    'hello     '
'Admin     '    'user      '    'user2     '    'hello123  '

As you can see this is 2x4 cell returned object. I want this cell to be converted into proper table or some format where I can access the exact row column entry. I am thinking to use this cell as it is but could not getting idea how to proceed. I want to access data with row_number and column number reference. Could someone please provide some help as this cell is not int proper row column format it is presenting one row as column.

Community
  • 1
  • 1
Abdul Rehman
  • 2,224
  • 25
  • 30

1 Answers1

1

That looks like you've got a 3x4 cell with the column header (numeric in this case) stuffed in the first row. If that's the case, you could just strip off the header.

datHeader = dat(1,:);
datRows = dat(2:end,:);

Then you can index into it with datRows{iRow}{iColumn}.

However, if you're working with larger data sets and have any numeric data, you'll probably want to convert the numeric columns from cell arrays to double arrays, and store your data as a cell array of column vectors instead of a 2-D cell array. And call deblank() on the char columns to trim off the trailing whitespace, which is appropriate for a 2-D char array but not for cellstrs.

Andrew Janke
  • 23,508
  • 5
  • 56
  • 85