필터 지우기
필터 지우기

how to transform data from excel to tesx

조회 수: 3 (최근 30일)
Muhsin
Muhsin 2017년 12월 19일
댓글: Walter Roberson 2017년 12월 19일
Hello all; Can anyone please help me transform the data from excel to txt in a format like the attached file? Thank you very much

채택된 답변

Walter Roberson
Walter Roberson 2017년 12월 19일
fid_in = fopen('input.csv', 'rt');
fid_out = fopen('output_file.txt', 'wt');
colname_line = fgetl(fid_in);
colnames = regexp(colname_line, '\s*\t\s*', 'split');
colnames_formatted = sprintf('$#%8s%10s%10s%10s%10s%10s%10s%10s', colnames{:});
empty_formatted = blanks(80);
while true
thisline = fgetl(fid_in);
if ~ischar(thisline); break; end %end of file detected
vals_in = sscanf(thisline, '%f');
fprintf(fid_out, '*PART\n$# title\n%s\n%s\n', empty_formatted, colnames_formatted);
fprintf(fid_out, '%10g%10g%10g%10g%10g%10g%10g%10g\n', vals_in);
end
fclose(fid_in);
fclose(fid_out);
"Bug-for-bug compatible" as they say in the industry...
  댓글 수: 2
Muhsin
Muhsin 2017년 12월 19일
Dear Walter; I dont know what is wrong with csv format of previous attached file. I have corrected. Can you please new csv file that is attached to this comment?
Walter Roberson
Walter Roberson 2017년 12월 19일
Change
colnames = regexp(colname_line, '\s*\t\s*', 'split');
to
colnames = regexp(colname_line, ',', 'split');
Change
vals_in = sscanf(thisline, '%f');
to
vals_in = sscanf(thisline, '%f,');

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by