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

6 ビュー (過去 30 日間)
Sumit Saha
Sumit Saha 2020 年 12 月 15 日
編集済み: Cris LaPierre 2021 年 1 月 6 日
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 Center および File ExchangeData 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