Created
May 5, 2011 00:18
-
-
Save mcandre/956299 to your computer and use it in GitHub Desktop.
Classify tumors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% classifyTumor.m | |
% Andrew Pennebaker | |
% 4 May 2011 | |
% Assumes matrix contains only one shape (short bar, long bar, square, L) | |
function classifyTumor(Matrix) | |
Cropped = crop(Matrix); | |
Size = size(Cropped); | |
M = Size(1); | |
N = Size(2); | |
% Short bar | |
if isequal(Size, [3 1]) || isequal(Size, [1 3]) | |
classification = 'benign'; | |
% Long bar | |
elseif M == 1 || N == 1 | |
classification = 'neither'; | |
% Squares and Ls | |
else | |
classification = 'malignant'; | |
end | |
classification | |
end | |
% Remove whitespace (0s) surrounding shapes in a matrix | |
function crop(Matrix) | |
% Crop top | |
while not(any(Matrix(1, :))) | |
Matrix = Matrix(2:end, :); | |
end | |
% Crop bottom | |
while not(any(Matrix(end, :))) | |
Matrix = Matrix(1:end - 1, :); | |
end | |
% Crop left | |
while not(any(Matrix(:, 1))) | |
Matrix = Matrix(:, 2:end); | |
end | |
% Crop right | |
while not(any(Matrix(:, end))) | |
Matrix = Matrix(:, 1:end - 1); | |
end | |
y = Matrix | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment