How to store values in a matrix using my for loop

Hi there,
I am having trouble moving through my code as i am trying to write the code for a pattern search after a classification map. i need to declare the classification map with the values that my for loop produces but i do not know how.
i have attached the code.
for row = 1: MAX_ROWS
for col = 1: MAX_COLS
value = rawData(row, col);
if value > 0 && value < rvavg1
fprintf('1 |');
elseif value > rvavg1 && value < 0.5
fprintf('2 |');
elseif value > 0.5 && value < rvavg2
fprintf('3 |');
elseif value > rvavg2 && value < 1
fprintf('4 |');
elseif value > 1 && value < rvavg3
fprintf('5 |');
elseif value > rvavg3 && value < 1.5
fprintf('6 |');
elseif value > 1.5 && value < rvavg4
fprintf('7 |');
elseif value > rvavg4 && value < 2
fprintf('8 |');
elseif value > 2 && value < rvavg5
fprintf('9 |');
elseif value > rvavg5 && value < 2.5
fprintf('10 |');
end
end
fprintf('\n')
end

Answers (1)

Just assign the value in the if statement, for example
fprintf('5 |');
classificationMap(row, column) = 5;
Before the loop, preallocate the array
classificationMap = zeros(MAX_ROWS, MAX_COLUMNS);

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 1 Oct 2017

Answered:

on 1 Oct 2017

Community Treasure Hunt

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

Start Hunting!