作者netsm (小黑)
看板MATLAB
標題[討論] 請教用function寫txt輸出,謝謝...
時間Fri Jun 24 15:46:32 2016
不好意思,請教一下,
我用MATLAB寫一個function要輸出txt檔,
可是好像不行,有人可以給建議嗎?
------
function Output_Data = output_txt_data( file_title, inputdata )
% file_title 是要輸出的檔案之檔名
% 要輸出的內容(數值)
fid = fopen('file_title','wt');
[ m, n ] = size(inputdata);
for i = 1 : 1 : m
for j = 1 : 1 : n
if j == 1
fprintf(fid, '%9.0f', inputdata(i, j));
elseif j == n
fprintf(fid, '%6.4f\n', inputdata(i,j));
else
fprintf(fid, '%9.4f\t\r', inputdata(i,j));
end
end
end
fclose(fid);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.238.117.86
※ 文章網址: https://webptt.com/m.aspx?n=bbs/MATLAB/M.1466754395.A.39B.html
1F:→ name0625: fid = fopen([file_title '.txt'],'wt'); 這樣試試看? 06/24 16:29
2F:→ netsm: 不行ㄟ... 06/25 02:03
3F:→ name0625: 我自己用是可以,你的不行是怎樣不行? 06/25 08:11
4F:推 x46824682x: 錯誤碼貼出來吧..這應該很簡單... 06/25 10:37
5F:→ netsm: Output argument "Output_Data" (and maybe others) not as 06/25 20:08
6F:→ netsm: not assigned during call to "output_txt_data". 06/25 20:09
7F:推 celestialgod: fopen('file_title','wt');改成fopen(file_title,'w 06/25 20:59
8F:→ celestialgod: t'); 06/25 20:59
9F:→ celestialgod: function Output_Data = output_txt_data( file_tit 06/25 21:01
10F:→ celestialgod: le, inputdata ) 改成 function [] = output_txt_da 06/25 21:01
11F:→ celestialgod: ta( file_title, inputdata ) 06/25 21:01
12F:→ netsm: 感謝以上各位高手熱心地回覆,我試出來了,謝謝... 06/30 15:17
13F:→ netsm: 改成... 06/30 15:18
14F:→ netsm: function output_txt_data( filename, inputdata ) 06/30 15:19
15F:→ netsm: fid = fopen([filename '.txt'],'wt'); 06/30 15:20
16F:→ netsm: 特別感謝一樓的大大,你的提示是對的,可是我忘了改第1行.. 06/30 15:22