This repository has been archived by the owner on Mar 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
read_array_impedances.m
71 lines (62 loc) · 1.75 KB
/
read_array_impedances.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
66
67
68
69
70
71
function [Zstruct] = read_array_impedances(varargin)
% [Zstruct] = read_array_impedances(varargin)
%
% Import impedances from a .txt file as generated by Cerebus into a
% Matlab structure
%
% Zstruct:
% |----> Info: cell array of info extracted from file header
% |----> Z : 96x1 vector of impedances values in KOhms
%
% varargin: file path and name as char array.
% If not provided, will prompt user.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Zstruct=[];
if nargin > 1
disp('Invalid number of argument');
return;
elseif nargin
filename = varargin{1};
if ~ischar(filename)
disp('Invalid argument');
return;
end
else
[filename, filepath] = uigetfile('*.txt','Please choose the impedance .txt file');
filename = [filepath filename];
end
fid = fopen(filename);
if fid<0
disp('Could not find that file');
return;
end
%Read Header
% could have used fstrvcat
infolines = cell(9,1);
line_idx = [];
line_len = zeros(9,1);
for i = 1:9
infolines{i} = strrep(fgetl(fid),'*','');
line_len(i) = length(infolines{i});
if line_len(i) > 0
line_idx = [line_idx i];
end
end
numlines = length(line_idx);
info = char(zeros(numlines,max(line_len)));
for i = 1:numlines
info(i,1:line_len(line_idx(i))) = infolines{line_idx(i)};
end
%Read Impedances
Z = -1*ones(96,1);
for i = 1:96
tmptxt = fgetl(fid);
%the text is like: ' chanxx zzz kOhm'
% '123456789012345789'
%it always have 19 characters, and
%impedances are between 8 and 14
Z(i) = str2double(deblank(tmptxt(8:14)));
end
Zstruct = struct('Z',Z,'info',info);
fclose(fid);