gen_mat5files.m 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. % Generates mat files for loadmat unit tests
  2. % This is the version for matlab 5 and higher
  3. % Uses save_matfile.m function
  4. % work out matlab version and file suffix for test files
  5. global FILEPREFIX FILESUFFIX
  6. FILEPREFIX = [fullfile(pwd, 'data') filesep];
  7. temp = ver('MATLAB');
  8. mlv = temp.Version;
  9. FILESUFFIX = ['_' mlv '_' computer '.mat'];
  10. % basic double array
  11. theta = 0:pi/4:2*pi;
  12. save_matfile('testdouble', theta);
  13. % string
  14. save_matfile('teststring', '"Do nine men interpret?" "Nine men," I nod.')
  15. % complex
  16. save_matfile('testcomplex', cos(theta) + 1j*sin(theta));
  17. % asymmetric array to check indexing
  18. a = zeros(3, 5);
  19. a(:,1) = [1:3]';
  20. a(1,:) = 1:5;
  21. % 2D matrix
  22. save_matfile('testmatrix', a);
  23. % minus number - tests signed int
  24. save_matfile('testminus', -1);
  25. % single character
  26. save_matfile('testonechar', 'r');
  27. % string array
  28. save_matfile('teststringarray', ['one '; 'two '; 'three']);
  29. % sparse array
  30. save_matfile('testsparse', sparse(a));
  31. % sparse complex array
  32. b = sparse(a);
  33. b(1,1) = b(1,1) + j;
  34. save_matfile('testsparsecomplex', b);
  35. % Two variables in same file
  36. save([FILEPREFIX 'testmulti' FILESUFFIX], 'a', 'theta')
  37. % struct
  38. save_matfile('teststruct', ...
  39. struct('stringfield','Rats live on no evil star.',...
  40. 'doublefield',[sqrt(2) exp(1) pi],...
  41. 'complexfield',(1+1j)*[sqrt(2) exp(1) pi]));
  42. % cell
  43. save_matfile('testcell', ...
  44. {['This cell contains this string and 3 arrays of increasing' ...
  45. ' length'], 1., 1.:2., 1.:3.});
  46. % scalar cell
  47. save_matfile('testscalarcell', {1})
  48. % Empty cells in two cell matrices
  49. save_matfile('testemptycell', {1, 2, [], [], 3});
  50. % 3D matrix
  51. save_matfile('test3dmatrix', reshape(1:24,[2 3 4]))
  52. % nested cell array
  53. save_matfile('testcellnest', {1, {2, 3, {4, 5}}});
  54. % nested struct
  55. save_matfile('teststructnest', struct('one', 1, 'two', ...
  56. struct('three', 'number 3')));
  57. % array of struct
  58. save_matfile('teststructarr', [struct('one', 1, 'two', 2) ...
  59. struct('one', 'number 1', 'two', 'number 2')]);
  60. % matlab object
  61. save_matfile('testobject', inline('x'))
  62. % array of matlab objects
  63. %save_matfile('testobjarr', [inline('x') inline('x')])
  64. % unicode test
  65. if str2num(mlv) > 7 % function added 7.0.1
  66. fid = fopen([FILEPREFIX 'japanese_utf8.txt']);
  67. from_japan = fread(fid, 'uint8')';
  68. fclose(fid);
  69. save_matfile('testunicode', native2unicode(from_japan, 'utf-8'));
  70. end
  71. % func
  72. if str2num(mlv) > 7 % function pointers added recently
  73. func = @afunc;
  74. save_matfile('testfunc', func);
  75. end