http://www.labfans.com/bbs/t11883/
首先,你要確定你要把待輸出的內容輸出到哪里,是文件里還是commend window。fprintf是把數據以一定格式輸出到一個文件里,disp是將提示字符串或變量值輸出到commend window,還可以輸出一個超鏈接。如:
fprintf:
x = 0:.1:1;
y = [x; exp(x)];
fid = fopen('exp.txt', 'wt');% 需要先打開一個文件
fprintf(fid, '% 6.2f %12.8f\n', y); %
fclose(fid)
disp:
disp(' Corn Oats Hay')
disp(rand(5,3))
結果在命令窗口顯示:
Corn Oats Hay
0.2113 0.8474 0.2749
0.0820 0.4524 0.8807
0.7599 0.8075 0.6538
0.0087 0.4832 0.4899
0.8096 0.6135 0.7741
另外:
disp('<a href = "http://www.mathworks.com">The MathWorks Web Site</a>')
顯示一個超鏈接: The MathWorks Web Site
fprintf:
x = 0:.1:1;
y = [x; exp(x)];
fid = fopen('exp.txt', 'wt');% 需要先打開一個文件
fprintf(fid, '% 6.2f %12.8f\n', y); %
fclose(fid)
disp:
disp(' Corn Oats Hay')
disp(rand(5,3))
結果在命令窗口顯示:
Corn Oats Hay
0.2113 0.8474 0.2749
0.0820 0.4524 0.8807
0.7599 0.8075 0.6538
0.0087 0.4832 0.4899
0.8096 0.6135 0.7741
另外:
disp('<a href = "http://www.mathworks.com">The MathWorks Web Site</a>')
顯示一個超鏈接: The MathWorks Web Site
__________________