필터 지우기
필터 지우기

How to break down a text file

조회 수: 2 (최근 30일)
jgillis16
jgillis16 2015년 6월 21일
댓글: Azzi Abdelmalek 2015년 6월 21일
I need to break down a text file into its respective columns. It has 6 columns. Would I format the code along the lines of something like this?
s271.1_hD = readCatalog(s27WHW02_LS220_j0_rx3_full_cc_fheat1.1_hD)
fid = fopen( 's27WHW02_LS220_j0_rx3_full_cc_fheat1.1_hD.txt');
data = textscan(fid, '%s', 'Delimiter', '\n', 'whitespace','');
fclose(fid);
list.time = data{1};
list.h+eq = data{2};
list.hxeq = data{3};
list.h+p = data{4};
list.hxp = data{5};
list.rho_c = data{6};
return
My file I need to break down is attached. Thank you!
  댓글 수: 1
per isakson
per isakson 2015년 6월 21일
편집: per isakson 2015년 6월 21일
I assume you want to convert to double. Try to replace
data = textscan(fid, '%s', 'Delimiter', '\n', 'whitespace','');
by
data = textscan( fid, '%f%f%f%f%f%f' );

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

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2015년 6월 21일
편집: Azzi Abdelmalek 2015년 6월 21일
You can use dlmread function
M=dlmread('s27WHW02_LS220_j0_rx3_full_cc_fheat1.1_hD.txt')
list=cell2struct(num2cell(M),{'f1' ,'f2','f3','f4','f5' ,'f6'},2)
  댓글 수: 2
jgillis16
jgillis16 2015년 6월 21일
How would I assign a variable to a specific column in 'M'? Say I wanted to assign X1 to the first column?

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Text Data Preparation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by