How to Read Data from one type of (.sema) file and to convert it into .txt file

조회 수: 6 (최근 30일)
I have 20000 (.sema) file and want to get .txt file from .sema file by excluding 1st column and first 11 rows. For example file name is acc_HXX_X_0_Y_0.
clear all
DATA_DIR = 'Desktop/subshear/subshear_acc/';
out_DIR = 'EQ/subshear/acc_files_subshear/';
x = [-30:5:30].*1e3;
y = [-30:5:30].*1e3;
[xx yy]=meshgrid(x,y);
nstat=length(xx);
nx = length(x);
ny = length(y);
kk=0;
for i=1:nx
for j=1:ny
kk=kk+1;
st_name=sprintf('X%dkY%dk',xx(kk)./1e3,yy(kk)./1e3);
filename = sprintf('%s/IND.%s.HXX.sema',DATA_DIR,st_name);
% fprintf(fid,'%s \t %s \t %f \t %f \t %f \t %f\n',st_name,'IND',yy(kk), xx(kk), 0.0, 0.0);
t_acc=load(filename,'r');
filename_acc = sprintf('%s/acc_%s.txt',out_DIR,st_name);
fid=fopen(filename_acc);
%fprintf(fid,'%g',t_acc(:,2));
%fclose(fid);
end
end

채택된 답변

Cris LaPierre
Cris LaPierre 2020년 12월 15일
편집: Cris LaPierre 2020년 12월 15일
Quick inspection suggests that your files are just text files with a custom extension. At least I can open them in a text editor and read them just fine.
MATLAB does try to determine file properties based on the extension. That will not be possible with this extension. However, you can still import the data. You just need to set some settings manually.
The file you mention is not in the zip file you shared. The 5 files you share all are 800x2. Here's how I might do it:
data = readmatrix("IND.X0kY0k.HXX.sema","FileType","text","Range",[12 2])
data = 789×1
7.151661e-13
2.853065e-12
4.9193176e-12
-3.5160106e-12
-4.2815907e-11
-1.1427437e-10
-1.2858667e-10
1.392735e-10
8.8575636e-10
1.7722569e-09
  댓글 수: 18
Sumit Saha
Sumit Saha 2021년 1월 6일
@Cris LaPierre How can I collect the names of files before converting these into serial order?
Cris LaPierre
Cris LaPierre 2021년 1월 6일
편집: Cris LaPierre 2021년 1월 6일
You can use the dir function to collect the contents in a folder. Perhaps my answer in this post might be helpful.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by