How to Read Data from one type of (.sema) file and to convert it into .txt file
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Sumit Saha
le 15 Déc 2020
Modifié(e) : Cris LaPierre
le 6 Jan 2021
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
0 commentaires
Réponse acceptée
Cris LaPierre
le 15 Déc 2020
Modifié(e) : Cris LaPierre
le 15 Déc 2020
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 commentaires
Cris LaPierre
le 6 Jan 2021
Modifié(e) : Cris LaPierre
le 6 Jan 2021
You can use the dir function to collect the contents in a folder. Perhaps my answer in this post might be helpful.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Import and Export dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!