-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremoveRowCol.m
More file actions
41 lines (33 loc) · 830 Bytes
/
removeRowCol.m
File metadata and controls
41 lines (33 loc) · 830 Bytes
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
% removeRowCol.m
% removes either the row or the columns that contain 0
function [rowRemoved1,rowRemoved2,colRemoved1,colRemoved2] = removeRowCol(matrix1, matrix2)
rowRemoved1 = matrix1;
rowRemoved2 = matrix2;
colRemoved1 = matrix1;
colRemoved2 = matrix2;
removeMatrix = [];
[m,n] = size(matrix1);
for i = 1:m
if ~any(matrix1(i,:))
removeMatrix(end+1) = i;
end
end
if ~isempty(removeMatrix)
rowRemoved1 = matrix1;
rowRemoved1(removeMatrix,:) = [];
rowRemoved2 = matrix2;
rowRemoved2(removeMatrix,:) = [];
end
removeMatrix = [];
for i = 1:n
if isempty(matrix1(:,i))
removeMatrix(end+1) = i; %#ok<*AGROW>
end
end
if ~isempty(removeMatrix)
colRemoved1 = matrix1;
colRemoved1(:,removeMatrix) = [];
colRemoved2 = matrix2;
colRemoved2(:,removeMatrix) = [];
end
end