필터 지우기
필터 지우기

how to convert matrix column into separate text?

조회 수: 3 (최근 30일)
Hydro
Hydro 2017년 6월 20일
댓글: Hydro 2017년 6월 21일
Hi all, I have a 365*45 matrix, which represents one-year data for 45 subbasins. I would like to convert each column of the matrix to a separate text file (45 text file with a year data) and naming the file as subbasin_1, subbasin_2 etc. Any thought would be highly appreciated.

채택된 답변

Rik
Rik 2017년 6월 20일
You obviously did not Google/Bing/Yahoo this.
You can use a loop, combined with sprintf to do this.
for n=1:45
filename=sprintf('subbasin_%d.txt',n);
fid=fopen(filename);
%
%put your writing code here
%
fclose(fid);
end
  댓글 수: 3
Walter Roberson
Walter Roberson 2017년 6월 21일
After the fopen() and before the fprintf(), add another fprintf() that puts in the header you want.
Hydro
Hydro 2017년 6월 21일
Excellent. Thank you Walter and Rik.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by