Creating a classification maps from a (20 x20) matrix of raw data

Hi can someone help me with how to write a mathlab code: Scenario is: r is a set of raw data in a (20 x 20 ) matrix.
action 1: I have to re- display the data in the (20 x20)matrix into another (20 x20) matrix that now takes the original data and classifies it as : if the data ranges between 0 -4.9 - it must display (1) if the data ranges between 4.9 - 8.0 - it must display (2) if the data ranges between 8.0 - 12.0 - it must display (3)
so essentially I end up with a new classification map of ( 20 x20) displaying either 1,2 or 3 in place of the original data.
action 2: I now need to build a counter , that counts how many times the 1,2, and 3 appears in the (20 x20) classification map .
any help, hints will be appreciated.

3 Comments

I assume this is homework. The best way for you to learn matlab is by first trying to solve the problem, not waiting for someone to get you started.
Once you've made a decent attempt, come back to us with a specific question (e.g. "why, when I do this, don't I get the right answer")
hi Guillaume, sorry , if fact I have tried to work it out but have come to a road block.
so far I have been able to get the file to read the raw data , as (r). but I have no idea how to write the if statements. this is what I have done so far :
% Reading the Raw date file
rawdata = dlmread ('data-1.csv',',');
disp (rawdata);
% roundOff rawdata to two decimal places
r = round(rawdata,2,'decimals');
disp (r);
this is where I'm unclear as to how I get the if statements to work my train of thought is :
if r <=4.9;
fprintf('1\n')
elseif r<=8.0;
fprintf('2\n');
so on and so forth.... if anyone could care to provide some hints on how to proceed it will be appreciated.
thanks
this is my code thus far : however i'm not getting the display of the classification map as a 20 x 20 , instead its just prints out as single colums with all the values of 1, 2,3,4,5.. any help as to why this is?
% Reading the Raw date file
rawdata = dlmread ('data-1.csv',',');
disp (rawdata);
% roundOff rawdata to two decimal places
r = round(rawdata,2,'decimals');
disp (r);
%Constants
MAX_ROWS = size(r,2);
MAX_COL = size(r,1);
MAX_RANGE = 5;
LOW_ERROR = 0.0;
HIGH_ERROR = 2.0;
PATTERN_A_CHAR = 'A';
PATTERN_B_CHAR = 'B';
PATTERN_C_CHAR = 'C';
NO_PATTERN_CHAR = '-1';
EMPTY = ' ';
%Variables
%Set up the range bounds
rangeValue1 = 0.4;
rangeValue2 = 0.8;
rangeValue3 = 1.2;
rangeValue4 = 1.6;
rangeValue5 = 2.0;
%Set up Display values
displayValue1 = 1;
displayValue2 = 2;
displayValue3 = 3;
displayValue4 = 4;
displayValue5 = 5;
%************************************
%Classification Map
Classification_Map = r(MAX_ROWS,MAX_COL);
for MAX_ROWS = 1:+1:20;
for MAX_COL = 1:+1:20;
if r(MAX_ROWS,MAX_COL)<= rangeValue1;
disp(displayValue1);
elseif r(MAX_ROWS,MAX_COL) <= rangeValue2;
disp(displayValue2);
elseif r(MAX_ROWS,MAX_COL) <= rangeValue3;
disp(displayValue3);
elseif r(MAX_ROWS,MAX_COL) <= rangeValue4;
disp(displayValue4);
elseif r(MAX_ROWS,MAX_COL) <= rangeValue5;
disp(displayValue5);
end
end
end

Sign in to comment.

 Accepted Answer

Since you didn't say that whether it's homework or not, I hope this is not too much of a hint:
minValue = -5; % Whatever...
maxValue = 20; % Whatever...
% Create random data.
r = minValue + (maxValue-minValue)*rand(20,20)
% Initialize a classification map to zeros.
classificationMap = zeros(size(r));
% Find out where class 1 pixels live.
class1Indexes = r > 0 & r < 4.9
% Assign those to "1" in the classification map.
classificationMap(class1Indexes) = 1
% Repeat for other classes
% Values outside class ranges will be zero,
% meaning not assigned to any class
If you still need help after that, say whether it's homework or not (and "tag" it as homework if it is), and ask your question.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!