Creating new text file
2 ビュー (過去 30 日間)
古いコメントを表示
I did this earlier but know it does not work. I'm trying to reformat a text file and print another one. When I run the code I turns back the following error:
Error using fprintf
Function is not defined for 'cell' inputs.
Error in P_format (line 36)
fprintf(fid, '%s %4s %4s %4s %4s %4s %4s\n', Pswmm{i,:});
Here is the code:
clear all
clc
%Format text data from NCDC website into SWMM5 compatible P .txt file
fid = fopen('C:\Users\sdehoyos\Desktop\Precip_448903Dulles_448906Reagan.txt');
A = textscan(fid, '%s %d %s %f', 'HeaderLines', '1');
fclose(fid);
COOPstationID=cellstr(cell2mat(A{1,1}));
Date=cellstr(num2str(A{1,2}));
Time=cellstr(cell2mat(A{1,3}));
Ptimes100=A{1,4};
for i=1:length(COOPstationID)
stationID{i,:}=cellstr({COOPstationID{i}(6:end)});
end
for i=1:length(Date)
Year{i,:}=cellstr({Date{i}(1:4)});
Month{i,:}=cellstr({Date{i}(5:6)});
Day{i,:}=cellstr({Date{i}(7:8)});
end
for i=1:length(Time)
Hour{i,:}=cellstr({Time{i}(1:2)});
Minute{i,:}={Time{i}(4:5)};
end
P=cellstr(num2str(Ptimes100/100));
Pswmm={stationID Year Month Day Hour Minute P};
fid = fopen('Pswmm.txt', 'w');
for i=1:length(Pswmm);
fprintf(fid, '%s %4s %4s %4s %4s %4s %4s\n', Pswmm{i,:});
end
fclose(fid);
0 件のコメント
回答 (1 件)
Azzi Abdelmalek
2013 年 8 月 30 日
Use square brackets []instead of curly bracket {}
Pswmm=[stationID Year Month Day Hour Minute P];
1 件のコメント
Image Analyst
2013 年 8 月 31 日
編集済み: Image Analyst
2013 年 8 月 31 日
That won't work either because the things in there (stationID, Year, etc.) are also cells.
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!