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!