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!