Subscripted assignment dimension mismatch in matlab -
i executed code using feature matrix 517*11 , label matrix 517*1. once dimensions of matrices change code cant run. how can fix this?
the error is:
subscripted assignment dimension mismatch. in line : edges(k,j) = quantlevels(a);
here code:
function [features,weights] = mi(features,labels,q) if nargin <3 q = 12; end edges = zeros(size(features,2),q+1); k = 1:size(features,2) minval = min(features(:,k)); maxval = max(features(:,k)); if minval==maxval continue; end quantlevels = minval:(maxval-minval)/500:maxval; n = histc(features(:,k),quantlevels); totsamples = size(features,1); n_cum = cumsum(n); edges(k,1) = -inf; stepsize = totsamples/q; j = 1:q-1 = find(n_cum > j.*stepsize,1); edges(k,j) = quantlevels(a); end edges(k,j+2) = inf; end s = zeros(size(features)); k = 1:size(s,2) s(:,k) = quantize(features(:,k),edges(k,:))+1; end = zeros(size(features,2),1); k = 1:size(features,2) i(k) = computemi(s(:,k),labels,0); end [weights,features] = sort(i,'descend'); %% eof function [i,m,sp] = computemi(seq1,seq2,lag) if nargin <3 lag = 0; end if(length(seq1) ~= length(seq2)) error('input sequences of different length'); end lambda1 = max(seq1); symbol_count1 = zeros(lambda1,1); k = 1:lambda1 symbol_count1(k) = sum(seq1 == k); end symbol_prob1 = symbol_count1./sum(symbol_count1)+0.000001; lambda2 = max(seq2); symbol_count2 = zeros(lambda2,1); k = 1:lambda2 symbol_count2(k) = sum(seq2 == k); end symbol_prob2 = symbol_count2./sum(symbol_count2)+0.000001; m = zeros(lambda1,lambda2); if(lag > 0) k = 1:length(seq1)-lag loc1 = seq1(k); loc2 = seq2(k+lag); m(loc1,loc2) = m(loc1,loc2)+1; end else k = abs(lag)+1:length(seq1) loc1 = seq1(k); loc2 = seq2(k+lag); m(loc1,loc2) = m(loc1,loc2)+1; end end sp = symbol_prob1*symbol_prob2'; m = m./sum(m(:))+0.000001; = sum(sum(m.*log2(m./sp))); function y = quantize(x, q) x = x(:); nx = length(x); nq = length(q); y = sum(repmat(x,1,nq)>repmat(q,nx,1),2);
i've run function several times without getting error. i've used input "seq1" , "seq2" arrays such 1:10 , 11:20
possible error might rise in loops
for k = 1:lambda1 symbol_count1(k) = sum(seq1 == k); end if "seq1" , "seq2" defined matrices since sum return array while symbol_count1(k) expected single value.
another possible error might rise if seq1 , seq2 not of type integer since used indexes in
m(loc1,loc2) = m(loc1,loc2)+1; hope helps.
Comments
Post a Comment