-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmamrimport.m
65 lines (50 loc) · 1.96 KB
/
mamrimport.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
function varname = mamrimport(filepath)
if strcmp(class(filepath),'double')
directory = dir;
filepath = [pwd '\' directory(filepath+2).name];
end
[~, filename, extension] = fileparts(filepath);
varname = filename; %Extract filename from path
varname = strrep(varname,'-','_'); %Change - to _
varname = genvarname(varname); %Ensure variable name is valid
DELIMITER = '\t';
HEADERLINES = 5000; % Should be larger than total lines in file
ImportedData = importdata(filepath,DELIMITER,HEADERLINES); % Import everything into dummy
numlines = length(ImportedData);
numsections = 0;
P = 0;
F = 0;
for i = 1:numlines % Find sections
if strfind(ImportedData{i},'Power [dBm]')
P = P+1;
Power{P} = str2double(ImportedData{i+1});
end
if strfind(ImportedData{i},'Frequency [GHz]')
F = F+1;
Freq{F} = str2double(ImportedData{i+1});
end
if strfind(ImportedData{i},'V_Hall')
numsections = numsections + 1;
sectionstart(numsections) = i;
end
end
DataStruct.Filepath = filepath;
fileinfo = dir(filepath);
DataStruct.FileDate = fileinfo.date;
for n = 1:numsections
ImportedData = importdata(filepath,DELIMITER,sectionstart(n)); % Import everything after @@Data +1 (this function will stop import at the next text line)
savecols = [1 2];
colnames = {'Field','V_Hall'};
for i = 1:length(savecols)
DataStruct.(colnames{i}) = ImportedData.data(:,savecols(i));
end
if P>=n && F>=n
DataStruct.Power = Power{n};
DataStruct.Freq = Freq{n};
end
if n==1
assignin('base',varname,DataStruct); %Import file as a struct into workspace
else
assignin('base',[varname '_' num2str(n)],DataStruct); % Append section number
end
end