Matlab编程技巧分享Matlab代码片段% 你好世界 fprintf( ' 你好世界!

' ); % 将 Hello World 写入文件 fid = fopen(' hello.txt ' , ' w ' ); fprintf(fid, ' 你好世界!

' ); fclose(fid); % 检查文件是否存在 if ~exist(' hello.txt ' , ' file ' ) % 不存在 else % 存在 end%% 随机数 % 设置随机数发生器的种子 rng( 0 , ' twister ' ); % 生成 [0..1] 范围内的随机数 rand % > 0.1711 % 生成 [a..b] 范围内的随机数 (b-a) * rand + a % > a = -5 % > b = 5 % > -4.6740 %% 从 [1..10] 中抽取整数