Creating new text file

4 visualizaciones (últimos 30 días)
Sergio
Sergio el 30 de Ag. de 2013
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);

Respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 30 de Ag. de 2013
Use square brackets []instead of curly bracket {}
Pswmm=[stationID Year Month Day Hour Minute P];
  1 comentario
Image Analyst
Image Analyst el 31 de Ag. de 2013
Editada: Image Analyst el 31 de Ag. de 2013
That won't work either because the things in there (stationID, Year, etc.) are also cells.

Iniciar sesión para comentar.

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by