AUV-Coop-Assembly
Master Thesis for Robotics Engineering. Cooperative peg-in-hole assembly with two underwater vehicles guided by vision
importMatrices.m
1 function matrix = importMatrices(filename)
2 
3 filename
4 
5 %# open file and read all lines
6 fid = fopen(filename, 'rt');
7 temp = textscan(fid, '%s', 'delimiter', '\n');
8 temp = [temp{:}];
9 fclose(fid);
10 
11 %# find empty lines
12 idxSep = find(cellfun(@isempty, temp));
13 %# separate matrices to different cells
14 temp2 = mat2cell(temp, diff([0; idxSep; numel(temp)]), 1);
15 %# remove empty lines
16 temp2(1:end-1) = cellfun(@(x) x(1:end-1), temp2(1:end-1), 'UniformOutput',0);
17 
18 %# convert cell arrays to double
19 out = cell(size(temp2));
20 for k = 1:numel(temp2)
21  out{k} = cellfun(@str2num, temp2{k}, 'UniformOutput',0);
22 end
23 out = cellfun(@cell2mat, out, 'UniformOutput', 0);
24 
25 matrix = zeros( size(out{1},1), size(out{1},2), length(out)-1);
26 for i = 1:(length(out)-1)
27  matrix(:,:,i) = out{i};
28 end
29 
30 
31