Path: news.mathworks.com!not-for-mail
From: "norton " <amz_ahmad@yahoo.com>
Newsgroups: comp.soft-sys.matlab
Subject: need quickly help to define matrix using variable
Date: Sat, 3 Apr 2010 14:08:05 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 47
Message-ID: <hp7i45$on2$1@fred.mathworks.com>
Reply-To: "norton " <amz_ahmad@yahoo.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1270303685 25314 172.30.248.38 (3 Apr 2010 14:08:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 3 Apr 2010 14:08:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2275761
Xref: news.mathworks.com comp.soft-sys.matlab:623165


asslamo alycom


i have a code to find the histogram of an image, and when i want to define the index of a matrix using a variable , it gives me an error:
here is the code below:


clear all;
close all;
clc
x = imread('s1.jpg');

h = rgb2gray(x);
imshow(h)
 m = size(x,1)
n = size(x,2)

r = 1;
r = repmat(r,1,255);



for k = 0 :1:255
    k = [k];
    n = 0;
    
    for i = 1: 305
        
        for j = 1:470
            
            if h(i,j)==k
                n  = n+1;
               
                n = [n];
            r(r) = k                   %%%%% here is the problem , i dont know why???
      
            end
        end
    end
end





plzzz help me quickly