2012-11-27 30 views
1

为以下几点:Matlab的:指数5×5网格点

x = [0.5 1.5 2.5 3.5 4.5]; 

    for k = 1:1:5 
     plot(x(k),x','b^','linewidth', 2) 
     hold on 
    end 

类似于:

[x,y] = meshgrid(0.5:1:4.5); 

我怎么可以指数的每个点(蓝色三角形)坐标?

enter image description here

结果应该是这样的:

point1 = [x(1),x(1)]; % [0.5,0.5] 
point2 = [x(1),x(2)]; % [0.5,1.5] 
point3 = [x(1),x(3)]; % [0.5,2.5] 
point4 = [x(1),x(4)]; % [0.5,3.5] 
point5 = [x(1),x(5)]; % [0.5,4.5] 
point6 = [x(2),x(1)]; % [1.5,0.5] 
... 
point25 = [x(5),x(5)];% [4.5,4.5] 

我必须做一些错误或MATLAB程序的心不是这些今天让我索引。

[~,idx] = length(point(:)); 
idxpoint = ind2sub(size(point),idx); 

请写一个工作示例。

预先感谢您。

+1

很抱歉,但我不明白你的问题。一个完全盲目的猜测,如果没有完全理解你的问题,我会说你应该看看重塑。 – 2012-11-27 18:58:26

回答

2

你几乎拥有了您可以使用meshgrid为:

x = linspace(0.5, 4.5, 5); 
y = linspace(0.5, 4.5, 5); 
[Y, X] = meshgrid(x, y); 

points = [X(:) Y(:)]; 

该方法具有可以使用不同优势x和y坐标。

现在的points商店x和y的每一行的坐标一点:

points(1,:) 
ans = 

0.5000 
0.5000 

points(25,:) 
ans = 

4.5000 
4.5000 
+0

一如既往的教育,做好@angainor。 – professor

1

可以叠加所有的点成N×2矩阵,代表一个点”

close all 
x = [0.5 1.5 2.5 3.5 4.5]; 
n = length(x); 
X = []; 

for k = 1:1:5 
    plot(x(k),x','b^','linewidth', 2) 
    X = [X; repmat(x(k),n,1) x']; 
    hold on 
end 

% replot on new figure 
figure, hold on 
plot(X(:,1),X(:,2),'b^','linewidth',2) 

% Each row of X is one of your points, i.e. 
% Point number 5: 
X(5,:) 
+0

谢谢你的方法。 – professor

1

怎么样以下?每行

[x y] = meshgrid(.5:1:4.5); 
points = [reshape(x,1,[])',reshape(y,1,[])'] 


points = 

0.5000 0.5000 
0.5000 1.5000 
0.5000 2.5000 
0.5000 3.5000 
0.5000 4.5000 
1.5000 0.5000 
1.5000 1.5000 
1.5000 2.5000 
1.5000 3.5000 
1.5000 4.5000 
2.5000 0.5000 
2.5000 1.5000 
2.5000 2.5000 
2.5000 3.5000 
2.5000 4.5000 
3.5000 0.5000 
3.5000 1.5000 
3.5000 2.5000 
3.5000 3.5000 
3.5000 4.5000 
4.5000 0.5000 
4.5000 1.5000 
4.5000 2.5000 
4.5000 3.5000 
4.5000 4.5000 
+0

谢谢我的观点。 – professor

+0

@pr教授,不客气 – Acorbe