Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Matlab code error

Subject: Matlab code error

From: Almas

Date: 24 Jun, 2011 15:10:21

Message: 1 of 2

Can any one help me out.... there are errors in this code
function distance = dtw(r,t)

[height width]=size(r);
[height2 width2] = size(t);

sum = 0;
sum2 = 0;

for i=1:height2
    for j=1:height
       

        for k=1:width2
            sum = sum + (abs(t(i,k)-r(j,k)));
        end
    
        local_dist(i,j) = sum;
        sum = 0;
    
    end
end

[height3 width3] = size(local_dist);

accum_dist(1,1) = local_dist(1,1);

    for x = 2:width3
    
        accum_dist(1,x) = accum_dist(1,x-1)+local_dist(1,x);
    
    end
    
    for y = 2:height3
    
        accum_dist(y,1) = accum_dist(y-1,1)+local_dist(y,1);
    
    end
    
for a = 2:height3
    for b = 2:width3
        
        accum_dist(a,b) = local_dist(a,b) + min([accum_dist(a-1,b) accum_dist(a,b-1) accum_dist(a-1,b-1)]);
        
    end
end

distance = accum_dist(height3, width3);

Subject: Matlab code error

From: Roger Stafford

Date: 24 Jun, 2011 18:01:05

Message: 2 of 2

"Almas" wrote in message <iu29ct$e9p$1@newscl01ah.mathworks.com>...
> Can any one help me out.... there are errors in this code
> function distance = dtw(r,t)
> ...........
 - - - - - - - -
  This is very awkward coding. In what respect are there errors in it? Does the system give an error message, are the results not what you expect, or does it run too slowly? In any case please give full details of what you find unsatisfactory about your function.

Roger Stafford

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us