From: <cde...@us...> - 2012-03-29 15:08:14
|
Revision: 10094 http://octave.svn.sourceforge.net/octave/?rev=10094&view=rev Author: cdemills Date: 2012-03-29 15:08:03 +0000 (Thu, 29 Mar 2012) Log Message: ----------- - Made the cast to 'char' more usefull Modified Paths: -------------- trunk/octave-forge/extra/dataframe/inst/@dataframe/subsasgn.m Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/subsasgn.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/subsasgn.m 2012-03-29 15:07:17 UTC (rev 10093) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/subsasgn.m 2012-03-29 15:08:03 UTC (rev 10094) @@ -30,7 +30,7 @@ if (isnull (df)) error ('dataframe subsasgn: first argument may not be empty'); endif - + switch (S(1).type) case '{}' error ('Invalid dataframe as cell assignement'); @@ -65,6 +65,19 @@ if (isnull(RHS)) error("Types can't be nulled"); endif if (1 == length (S)) %# perform explicit cast on each column + switch (RHS) + case {'char'} + for indj = (1:df._cnt(2)) + if (isnumeric (df._data{indj}) || islogical (df._data{indj})) + df._data(indj) = cellfun (@(x) cellstr (num2str(x, "%f")), \ + df._data(indj), + "UniformOutput", false); + endif + endfor + otherwise + df._data = cellfun (@(x) cast (x, RHS), df._data, + "UniformOutput", false); + endswitch df._data = cellfun (@(x) cast (x, RHS), df._data, "UniformOutput", false); df._type(1:end) = RHS; @@ -81,8 +94,17 @@ else indj = S(2).subs{1}; ncol = length (indj); endif - df._data(indj) = cellfun (@(x) cast (x, RHS), df._data(indj), - "UniformOutput", false); + switch (RHS) + case {'char'} + if (isnumeric (df._data{indj}) || islogical (df._data{indj})) + df._data(indj) = cellfun (@(x) cellstr (num2str(x, "%f")), \ + df._data(indj), + "UniformOutput", false); + endif + otherwise + df._data(indj) = cellfun (@(x) cast (x, RHS), df._data(indj), + "UniformOutput", false); + endswitch df._type(indj) = {RHS}; endif return @@ -180,9 +202,7 @@ if (~isnull (RHS)) S(1).subs{1} = indr; S(1).subs{2} = indc; endif - df = df_matassign (df, S, indc, ncol, RHS); - endswitch %# disp("end of subasgn"); keyboard This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |