MATLAB: Why the error is coming errorimage processing Trying to execute this code but it shows error "Subscript indices must either be real positive integers or logicals." [M,N]=size(x); y=zeros(1,N); for l=1:N sum1=sum(x(:,l).*log(x(:,l))); sum1=-1*sum1; y(1,l)=sum1; end Best Answer who is x?That message is the result of trying to access an non-existent element of the array, such as x(0).Make sure x has the right size.By the way, your for-loop codex= rand(3,4); % sample data[M,N]=size(x); y=zeros(1,N); for l=1:N sum1=sum(x(:,l).*log(x(:,l))); sum1=-1*sum1; y(1,l)=sum1; endIs the same that this, in a single line:for l=1:N y(l) = -( sum(x(:,l).*log(x(:,l))) );end Related SolutionsMATLAB: The code gives an error You are using sum as a variable, and as a function insum = sum+A(i,j)*X(j,1);d = sum(Z); MATLAB: Sliding window operation in image Try conv2(), imfilter(), nlfilter(), or, if you want to move in "jumps" instead of by one pixel, blockproc(). Related QuestionFor some reason every time I try to test the forward elimination function there is an error in the sum part, I cannot figure out why or what else I need to adAm I getting the error “Array indices must be positive integers or logical values”??? Undefined function or method ‘ddft’ for input arguments of type ‘double’.The variable Edj appears to change size consider preallocating
Best Answer