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:
Linspace at a diagonal

Subject: Linspace at a diagonal

From: Eric

Date: 27 Mar, 2009 15:05:18

Message: 1 of 5

I have a large grid of points and want to take the linspace across the diagonal (45 degree angle). How does one do this?

Subject: Linspace at a diagonal

From: Jos

Date: 27 Mar, 2009 15:30:19

Message: 2 of 5

"Eric " <ericbchang@hotmail.com> wrote in message <gqipve$rln$1@fred.mathworks.com>...
> I have a large grid of points and want to take the linspace across the diagonal (45 degree angle). How does one do this?

I do not understand your problem. Can you give a small example of the expected input and output?

Jos

Subject: Linspace at a diagonal

From: Matt Fig

Date: 27 Mar, 2009 15:52:01

Message: 3 of 5

Are you talking about this, for example:

N = 6;
A = magic(N)
A(N:N-1:N^2-1)

if you want the other diagonal, you could use diag or

A(1:N+1:N^2)

Subject: Linspace at a diagonal

From: Roger Stafford

Date: 27 Mar, 2009 17:39:01

Message: 4 of 5

"Eric " <ericbchang@hotmail.com> wrote in message <gqipve$rln$1@fred.mathworks.com>...
> I have a large grid of points and want to take the linspace across the diagonal (45 degree angle). How does one do this?

  You have not described your problem well, Eric, and we have to resort to wild guesses. Perhaps you mean something like the following. Assume your grid is m by n points. For some a and b do this:

 t = linspace(a,b,m+n-1);
 M = hankel(t(1:m),t(m:m+n-1));

  For the other diagonal direction, you would use the 'toeplitz' function.

Roger Stafford

Subject: Linspace at a diagonal

From: Eric

Date: 30 Mar, 2009 14:39:01

Message: 5 of 5

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gqj2vl$sv5$1@fred.mathworks.com>...
> "Eric " <ericbchang@hotmail.com> wrote in message <gqipve$rln$1@fred.mathworks.com>...
> > I have a large grid of points and want to take the linspace across the diagonal (45 degree angle). How does one do this?
>
> You have not described your problem well, Eric, and we have to resort to wild guesses. Perhaps you mean something like the following. Assume your grid is m by n points. For some a and b do this:
>
> t = linspace(a,b,m+n-1);
> M = hankel(t(1:m),t(m:m+n-1));
>
> For the other diagonal direction, you would use the 'toeplitz' function.
>
> Roger Stafford
I am trying to generate a 3D array plot using the meshgrid function. I am trying to isolate this generated plot into three bands (x axis, y axis, 45 degree line). I was able to generate the x and y axes, but am having difficulties isolating a 45 degree line. This is a sample of the code for the x and y axes.
[XX1,YY1] = meshgrid(linspace(min(xx),0.048,150),linspace(-0.035,-0.036,150));
[XX2,YY2] = meshgrid(linspace(0.048,0.049,150),linspace(-0.035,max(yy),150));
for tt = 1:1:nn,
    waitbar(tt/nn,h)
    cc=cc+1;
    zz= time_resp(:,tt);
    Wf1(:,:,cc)= griddata(xx,yy,zz,XX1,YY1,'linear');
    Wf2(:,:,cc)= griddata(xx,yy,zz,XX2,YY2,'linear');
pcolor(XX1,YY1,Wf1(:,:,cc));
    pcolor(XX2,YY2,Wf2(:,:,cc));
caxis([0.0 0.0003]), axis off, %
    C=colormap(gray); C=C(64:-1:1,:); colormap(C);
    shading interp;
    axis equal;
    
    M(:,cc)=getframe;
end

The numbers 0.048,-0.035 are just an arbitrary point on the plot.

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