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:
loop, simple script!

Subject: loop, simple script!

From: Z A

Date: 10 Sep, 2011 15:47:28

Message: 1 of 3

Hello all,

I need some help in running a simple loop, as you can I am having problems!
Consider the following:
x y
29.82 18.737
29.761 18.601
29.776 18.624
29.782 18.578
29.678 18.62
29.757 18.556
29.757 18.59
29.738 18.635
29.741 18.656
29.729 18.646
29.774 18.633
29.731 18.592
29.676 18.736
29.718 18.795
29.707 18.821
29.706 18.855
29.73 18.928
29.678 18.948
29.695 18.874

I want to find the displacement between each interval so something like
d1=sqrt((x.'(:,2)-x.'(:,1)).^2+(y.'(:,2)-y.'(:,1)).^2);
so for that case d1=0.14825. How do I write it in such a way that I can generate all? So next one would be d2=sqrt((x.'(:,3)-x.'(:,2)).^2+(y.'(:,3)-y.'(:,2)).^2); d1=sqrt((x.'(:,4)-x.'(:,3)).^2+(y.'(:,4)-y.'(:,3)).^2); etc...Rather than doing it individually! As you can see I took the transpose of x and y, is there a way where I don't need to do that as they are columns?

I appreciate the assistance!

Subject: loop, simple script!

From: Z A

Date: 10 Sep, 2011 15:53:08

Message: 2 of 3

Sorry, but I had to take the transpose and then apply d1=sqrt((x(:,2)-x(:,1)).^2+(y(:,2)-y(:,1)).^2); etc... for the others: d2=sqrt((x(:,3)-x(:,2)).^2+(y(:,3)-y(:,2)).^2); d1=sqrt((x(:,4)-x(:,3)).^2+(y(:,4)-y(:,3)).^2). How do I write a simple script that does exactly that for those columns without first taking the transpose of x and y then applying the above equations?

Much appreciated!

"Z A" <nospam-rekabi570@yahoo.ca> wrote in message <j4g0qg$d7l$1@newscl01ah.mathworks.com>...
> Hello all,
>
> I need some help in running a simple loop, as you can I am having problems!
> Consider the following:
> x y
> 29.82 18.737
> 29.761 18.601
> 29.776 18.624
> 29.782 18.578
> 29.678 18.62
> 29.757 18.556
> 29.757 18.59
> 29.738 18.635
> 29.741 18.656
> 29.729 18.646
> 29.774 18.633
> 29.731 18.592
> 29.676 18.736
> 29.718 18.795
> 29.707 18.821
> 29.706 18.855
> 29.73 18.928
> 29.678 18.948
> 29.695 18.874
>
> I want to find the displacement between each interval so something like
> d1=sqrt((x.'(:,2)-x.'(:,1)).^2+(y.'(:,2)-y.'(:,1)).^2);
> so for that case d1=0.14825. How do I write it in such a way that I can generate all? So next one would be d2=sqrt((x.'(:,3)-x.'(:,2)).^2+(y.'(:,3)-y.'(:,2)).^2); d1=sqrt((x.'(:,4)-x.'(:,3)).^2+(y.'(:,4)-y.'(:,3)).^2); etc...Rather than doing it individually! As you can see I took the transpose of x and y, is there a way where I don't need to do that as they are columns?
>
> I appreciate the assistance!

Subject: loop, simple script!

From: TideMan

Date: 10 Sep, 2011 22:28:59

Message: 3 of 3

On Sep 11, 3:53 am, "Z A" <nospam-rekabi...@yahoo.ca> wrote:
> Sorry, but I had to take the transpose and then apply d1=sqrt((x(:,2)-x(:,1)).^2+(y(:,2)-y(:,1)).^2); etc... for the others: d2=sqrt((x(:,3)-x(:,2)).^2+(y(:,3)-y(:,2)).^2); d1=sqrt((x(:,4)-x(:,3)).^2+(y(:,4)-y(:,3)).^2). How do I write a simple script that does exactly that for those columns without first taking the transpose of x and y then applying the above equations?
>
> Much appreciated!
>
> "Z A" <nospam-rekabi...@yahoo.ca> wrote in message <j4g0qg$d7...@newscl01ah.mathworks.com>...
> > Hello all,
>
> > I need some help in running a simple loop, as you can I am having problems!
> > Consider the following:
> > x                y
> > 29.82      18.737
> > 29.761     18.601
> > 29.776     18.624
> > 29.782     18.578
> > 29.678     18.62
> > 29.757     18.556
> > 29.757     18.59
> > 29.738     18.635
> > 29.741     18.656
> > 29.729     18.646
> > 29.774     18.633
> > 29.731     18.592
> > 29.676     18.736
> > 29.718     18.795
> > 29.707     18.821
> > 29.706     18.855
> > 29.73      18.928
> > 29.678     18.948
> > 29.695     18.874
>
> > I want to find the displacement between each interval so something like
> > d1=sqrt((x.'(:,2)-x.'(:,1)).^2+(y.'(:,2)-y.'(:,1)).^2);
> > so for that case d1=0.14825. How do I write it in such a way that I can generate all? So next one would be d2=sqrt((x.'(:,3)-x.'(:,2)).^2+(y.'(:,3)-y.'(:,2)).^2); d1=sqrt((x.'(:,4)-x.'(:,3)).^2+(y.'(:,4)-y.'(:,3)).^2); etc...Rather than doing it individually! As you can see I took the transpose of x and y, is there a way where I don't need to do that as they are columns?
>
> > I appreciate the assistance!

dx=diff(x);
dy=diff(y);
ds=abs(dx+i*dy);

Tags for 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