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

1 次查看(过去 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