cell2mat error in datafetch

1 view (last 30 days)
neo
neo on 22 Sep 2011
Hi,
I have a MATLAB code that fetches data from database( n rows of 2 columns) after which cell2mat function is applied on the result set:
sql_n= strcat('Select de1, de2 from pm..pm_mast where index_type = ''IC_Scenario1''' );
IC_Sn = str2num(cell2mat(fetch(conn,sql_n)));
sn_vector = sortrows(IC_Sn,1);
Sret(:,1) = sn_vector(:,2);
And i get the following error: CAT arguments dimensions are not consistent.
Error in ==> cell2mat at 89
m{n} = cat(1,c{:,n});
I connect to Oracle 11g in this code. The result of the DB query has rows like this:
32 0
91 -1.6
63 0.1000375
Basically we are converting the client's code from Sybase to Oracle and this functions seems to be running fine on Sybase side.
Does something extra needs to be done on the Oracle side MATLAB code to get the cell2mat function to work properly?
  1 Comment
Jan
Jan on 22 Sep 2011
Please format the code. Follow the "Markup help" link on this page to learn more about formatting.

Sign in to comment.

Answers (1)

Jan
Jan on 22 Sep 2011
1. Why do you use STRCAT if you have a single input string only? Then there is nothing to concatenate:
sql_n = strcat('Select de1, de2 from pm..pm_mast where index_type = ''IC_Scenario1''' );
% Shorter:
sql_n = 'Select de1, de2 from pm..pm_mast where index_type = ''IC_Scenario1''';
The data replied from the database as a cell do not have the same number of elements in each row. Then CELL2MAT is not able to convert them into a matrix, because a matrix must have the same number of elements in each row. So it is not a fault of CELL2MAT, but of inconsistent data.
Please inspect the value of:
fetch(conn,sql_n)
There are more efficient methods to convert a cell to a matrix than STR2NUM(CELL2MAT()).
[EDITED] If the data obtained by FETCH is a cell, which contains DOUBLE [1xN] vectors of different lengths, this might do, what you need:
C = fetch(conn, sql_n);
Len = cellfun('size', C, 2);
N = numel(C);
IC_Sn = zeros(N, max(Len)); % or NaN(N, Len)? [BUGFIX]
for i = 1:N
IC_Sn(1:Len(i)) = C{i};
end
Then IC_Sn is a padded matrix.
  6 Comments
Jan
Jan on 22 Sep 2011
It must be "IC_Sn=zeros(N, max(Len))". A bugfix is inserted.
neo
neo on 22 Sep 2011
I still get the same scalar error:
this is how my code looks like:
Temp_IC_Sn = fetch(conn, sql_Sn);
Len = cellfun('size', Temp_IC_Sn, 2);
N = numel(Temp_IC_Sn);
IC_Sn = zeros(N, max(Len));
for i = 1:N
IC_Sn(1:Len(i)) = Temp_IC_Sn{i};
end
ic_vector = sortrows(IC_Sn,1);
Sret(:,1) = ic_vector(:,2);

Sign in to comment.

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!