From: radar on
I have a 500,000 x 3 cellarray with the first col being a sql server datetime string

Is there a better way than shown below to copy the cell array to a matrix of the same dimension while converting the first col values to datenums

mat=zeros(size(ca));

for k = 1:length(ca)
mat(k,1) = datenum(ca{k,1})
mat(k,2) = ca{k,2}
mat(k,3) = ca{k,3}
end;
From: Walter Roberson on
radar wrote:
> I have a 500,000 x 3 cellarray with the first col being a sql server datetime string

> Is there a better way than shown below to copy the cell array to a matrix of the same dimension while converting the first col values to datenums

> mat=zeros(size(ca));
>
> for k = 1:length(ca)
> mat(k,1) = datenum(ca{k,1})
> mat(k,2) = ca{k,2}
> mat(k,3) = ca{k,3}
> end;

I would suggest trying the timing of this:

mat(:,1) = datenum(ca(:,1));
mat(:,2) = cell2mat(ca(:,2));
mat(:,3) = cell2mat(ca(:,3));
From: radar on
*Walter--Thanks--much faster*