0
votes

I make point plots like this one:

enter image description here

But now I need to plot all the lines between the points as well to create rectangular mesh under a deformation (i.e. do the connection to the closest neighbors in x and y direction - not connect all the points with all the points).

How can I convince matlab/octave to do that?

The code I have used is here:

%T,H,W and k are defined above, it doesn't matter for the plot.
for ii=1:2:H
for jj=1:2:W
    k=0.1;
    x=jj;
    y=ii;
    U(ii,jj)=7*exp(0.05*(y-H))*cos(k*x-T);
    V(ii,jj)=4*exp(0.1*(y-H))*sin(k*x-T);
    X(ii,jj)=jj;
    Y(ii,jj)=ii;
end
end
    plot(X+U,Y+V,'k.');
1
when you say "all the lines between the points" do you mean you want N lines drawn from each point to all of the N points? - GameOfThrows
No, just to the rectangular neighbors (it's not longer rectangular cause there is a deformation, but you know what I mean) - to the closest in x and y direction. - Victor Pira
To be able to do that you need to know wich points are connecter to wich ones beforehand. - Ander Biguri

1 Answers

1
votes

A plot as you want it is easily done with mesh(X,Y,Z). The problem with your code is that you have a lot of zeros in your matrices. These might be intentional. In that case I could provide another solution. But mesh() connects neighboring points in a matrix. Therefore having the 0 in every second line and row would connect every point to (0,0). The easiest way is to just let your ii,jj grow in steps of 1.

%T,H,W and k are defined above, it doesn't matter for the plot.
H = 20;
W = 40;
T = 2*pi;
for ii=1:1:H
for jj=1:1:W
    k=0.1;
    x=jj;
    y=ii;
    U(ii,jj)=7*exp(0.05*(y-H))*cos(k*x-T);
    V(ii,jj)=4*exp(0.1*(y-H))*sin(k*x-T);
    X(ii,jj)=jj;
    Y(ii,jj)=ii;
end
end
    plot(X+U,Y+V,'k.');
    hold on
    mesh(X+U, Y+V, zeros(size(X)));