# HG changeset patch # User Erik Kjellson # Date 1353527887 -3600 # Node ID 1feb913c34cac00605315f1fdd8fcde4a9828d94 # Parent 9aa8dcf1e93d455db1d80206a8b2ef0b190d65ad importdata.m: Correction for non-numeric data and added test for complex numbers. diff -r 9aa8dcf1e93d -r 1feb913c34ca scripts/io/importdata.m --- a/scripts/io/importdata.m Wed Nov 21 11:32:35 2012 -0500 +++ b/scripts/io/importdata.m Wed Nov 21 20:58:07 2012 +0100 @@ -259,6 +259,15 @@ delimiter_pattern, "split"))); endfor + ## FIXME: Make it behave like Matlab when importing a table where a whole + ## column is text only. E.g. + ## abc 12 34 + ## def 56 78 + ## This would give a 3x2 data matrix with the left column = nan(2,1), and + ## the text would end up in textdata. + ## In Matlab the data matrix would only be a 2x2 matrix, see example at: + ## http://www.mathworks.se/help/matlab/import_export/import-numeric-data-and-header-text-from-a-text-file.html + ## Go through the data and put it in either output.data or ## output.textdata depending on if it is numeric or not. output.data = NaN (length (file_content_rows) - header_rows, data_columns); @@ -273,7 +282,7 @@ ## output.data, otherwise in output.textdata if (!isempty (row_data{j})) data_numeric = str2double (row_data{j}); - if (!isempty (data_numeric)) + if (!isnan (data_numeric)) output.data(i-header_rows, j) = data_numeric; else output.textdata{i,j} = row_data{j}; @@ -387,6 +396,19 @@ %! assert (h, 0); %!test +%! # Complex numbers +%! A = [3.1 -7.2 0-3.4i; 0.012 -6.5+7.2i 128]; +%! fn = tmpnam (); +%! fid = fopen (fn, "w"); +%! fputs (fid, "3.1\t-7.2\t0-3.4i\n0.012\t-6.5+7.2i\t128"); +%! fclose (fid); +%! [a,d,h] = importdata (fn, "\\t"); +%! unlink (fn); +%! assert (a, A); +%! assert (d, "\t"); +%! assert (h, 0); + +%!test %! # Missing values %! A = [3.1 NaN 0; 0.012 6.5 128]; %! fn = tmpnam ();