-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmtx2vct.m
91 lines (72 loc) · 1.53 KB
/
mtx2vct.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
% MTX2VCT
%
% Function MTX2VCT transforms matrices into single vector.
%
% [vct,row,col] = mtx2vct(M_1,M_2,...,M_n)
%
% where
%
% vct:value - is output vector of all matrices elements
% row:value - is output vector that includes list of number of matrices-rows
% col:value - is output vector that includes list of number of matrices-columns
% M_k:value - are input matrices to be transformed into vector
%
% juraj.oravec@stuba.sk
%
% est.2014.02.10.
%
%
% See also VCT2MTX
% External Deps: None
% Internal Deps: add02mtz, add02mtz_item
function [vct,row,col] = mtx2vct(varargin)
Min = varargin;
% Vectors of Rows and Columns
%
for k = 1 : length(Min)
row(k,1) = size(Min{k},1);
col(k,1) = size(Min{k},2);
end % for k
% Add Zeros to Matrices
%
M0 = add02mtz(Min);
% Colapse Matrices into Single Matrix
%
M = [];
for k = 1 : size(M0)
M = [M; M0{k}];
end % for k
% Create Vector of Matrix Elements
%
vct = M(:);
end % function
%%
function M = add02mtz(Min)
%
% Add Zeros To Cell-array of Matrices
%
n = length(Min);
% Find Matrix with Maximal Number of Columns
%
col_max = -Inf;
for k = 1 : n
col_item = size(Min{k},2);
if(col_max < col_item)
col_max = col_item;
end % if
end % for n
% Add Zeros into All the Other Matrices
%
for k = 1 : n
M{k,1} = add02mtz_item(Min{k},size(Min{k},1),col_max);
end % for n
end % function
%%
function M = add02mtz_item(Min,row_max,col_max)
%
% Add Zeros To Single Matrix
%
M = zeros(row_max,col_max);
[row,col] = size(Min);
M(1:row,1:col) = Min;
end % function