Borrar filtros
Borrar filtros

How can I surf a non square matrix?

10 visualizaciones (últimos 30 días)
Sebastian
Sebastian el 2 de En. de 2014
Comentada: Sebastian el 2 de En. de 2014
I have a code which I want to plot in a rectangular shape. I want to surf a 5X3 rectangle filled with small squares (In this case it will be filled with 15 small squares). The problem is that the function surf does not let me to do that because it need to be a square matrix, that is why I need to do a 5X5 square matrix (In this case it is filled with 25 small squares). Is there a way to plot it with the 5X3 shape?
Here is my code:
x=linspace(0,100,5)
y=linspace(0,7,5)
X=repmat(x,5,1)
Y=repmat(y',1,5)
m=linspace(1,100,25) %Number every point
a=vec2mat(m,5) %Area of the rectangle
n=5 %realizations for vector
n2=5 %realizations for column
T = []
r=1:5
r2=1:5
P=repmat(r,5,1) %dijx
P2=repmat(r2',1,5) %dijy
T2=reshape(P',1,25) %dijx vector
T3=[]
for j=1:n2
for i=1:n
pointx=T2
point2x=meshgrid(i,1)
if pointx==point2x
point2x=pointx+i
elseif pointx==point2x
point2x=pointx-1
end
dijx=abs(pointx-point2x) %every row of dijx
T3=[T3;dijx]
end
end
T4=reshape(P2',1,25) %dijy vector
T5=[]
for i=1:n2
for i2=1:n
pointy=T4
point2y=meshgrid(i,1)
if pointy==point2y
point2y=pointy+i
elseif pointy==point2y
point2y=pointy-1
end
dijy=abs(pointy-point2y) %every row of dijy
T5=[T5;dijy]
end
end
Lx=20; %Length of the field in the x axis
Ly=3.5; %Length of the field in the y axis
Pij=exp(-sqrt((T3/Lx).^2+(T5/Ly).^2)); %correlation function
std=.125; %standard deviation given by TxDot (1-1.5%)
std2=std.^2;
Aij=std2*Pij;
C=chol(Aij,'lower'); %Cholesky decomposition(lower diagonal)
R = normrnd(7,1.25,[25 1]); %standard normally distribuited values with mean of 0 and standard deviation of 1
M=R*.7; %mean given by TxDot (5-9%)
g=(C*R)+(M); %vector g
figure;
surf(X,Y,reshape(g,5,5)); view(2); colorbar;
x2=linspace(0,100,5)
y2=linspace(0,7,5)
[X2 Y2]=meshgrid(x2,y2)
R2 = normrnd(7,1,[25 1]); %standard normally distribuited values with mean of 0 and standard deviation of 1
figure(2)
pcolor(X2,Y2,reshape(R2,5,5)); view(2); colorbar;

Respuesta aceptada

Kelly Kearney
Kelly Kearney el 2 de En. de 2014
Probably just an aspect ratio issue:
data = rand(5,3); % replace with your data
pltdata = nan(size(data)+1);
pltdata(1:end-1,1:end-1) = data;
pcolor(pltdata)
axis equal
Note that pcolor drops the edge values; I've added NaNs so the entire matrix is visible. You don't need the padding if you use imagesc instead:
imagesc(data);
axis equal;
  1 comentario
Sebastian
Sebastian el 2 de En. de 2014
This is what I was looking for, Thank you very much!

Iniciar sesión para comentar.

Más respuestas (1)

Walter Roberson
Walter Roberson el 2 de En. de 2014
surf() does not need the matrix to be square.
surf(rand(25, 33))
  3 comentarios
Walter Roberson
Walter Roberson el 2 de En. de 2014
I do not see any filling in the existing code? I see two different figures.
Which variable do you expect to display as the 5 x 3 rectangle, and which variable do you expect to display as the 5 x 5 squares inside the 5 x 3 rectangle?
Sebastian
Sebastian el 2 de En. de 2014
The 2 figures are 5X5 squares, I want to make them 5X3, but when I try to do that, instead of having 20 small squares I have 15 rectangles. I want to make a rectangle of 15 squares. Is that possible?

Iniciar sesión para comentar.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by