changeset 9908:56ae3eaf8fde octave-forge

- Made the cast to 'char' more usefull
author cdemills
date Thu, 29 Mar 2012 15:08:03 +0000
parents ea2023de7d8f
children f769e77b4dd3
files extra/dataframe/inst/@dataframe/subsasgn.m
diffstat 1 files changed, 25 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/extra/dataframe/inst/@dataframe/subsasgn.m	Thu Mar 29 15:07:17 2012 +0000
+++ b/extra/dataframe/inst/@dataframe/subsasgn.m	Thu Mar 29 15:08:03 2012 +0000
@@ -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