How can I surf a non square matrix?
10 ビュー (過去 30 日間)
古いコメントを表示
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;
0 件のコメント
採用された回答
Kelly Kearney
2014 年 1 月 2 日
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 件)
Walter Roberson
2014 年 1 月 2 日
surf() does not need the matrix to be square.
surf(rand(25, 33))
3 件のコメント
Walter Roberson
2014 年 1 月 2 日
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?
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!