Try this. Firstly read the file into a string (note that I removed the space at the end of the filename):
str = fileread('STIFFNESS MATRIX.txt');
Then extract the data from the block headers, including the row numbers:
[tok,idx] = regexp(str, 'ROW\s+(\d+)\s+NODE\s+(\d+)\s+[^\n=]+=\s+(\w+)', 'tokens', 'end');
tok = vertcat(tok{:});
idx = [1+idx,numel(str)];
Extract the data from the blocks:
fun = @(b,e)reshape(sscanf(str(b:e),'%f'),2,[]).';
mat = arrayfun(fun, idx(1:end-1), idx(2:end), 'UniformOutput',false);
Convert the data from string into numeric:
fun = @(r,v)[sscanf(r,'%i')*ones(size(v,1),1),v];
mat = cellfun(fun, tok(:,1), mat(:), 'UniformOutput',false);
mat = vertcat(mat{:});
And finally transfer the numeric data into one single numeric array, by using the row and column indices to allocate the data:
out = zeros(size(tok,1));
ind = sub2ind(size(out),mat(:,1),mat(:,2));
out(ind) = mat(:,3)
This gives one matrix containing the complete data:
>> out
out =
1.0e+09 *
Columns 1 through 14
0.1351 0 0.0915 -0.0591 0 0 0 -0.3660 0 0 0 ...
Columns 15 through 18
0 0 0 0
0 0 0 0
...
0 0 0 0
0 0 0 0
1.4636 -0.0000 0 0
-0.0000 0.0138 0.0001 0
0 0.0001 0.5012 0
0 0 0 0.5180
Best Answer
Try this: