可以使用fopen、fprintf、fclose流程。比如:

% by lyqmath
clc; clear all; close all;
str = 'hello';
fid = fopen('c:\\ceshi.txt', 'wt');
fprintf(fid, str);
fid = fclose(fid);

结果