简体   繁体   English

如何将x,y,z坐标输入为矩阵内的单个元素?

[英]How do I input x,y,z co-ordinates as a single element inside a matrix?

I am trying to create a bezier surface using MATLAB code. 我正在尝试使用MATLAB代码创建贝塞尔曲面。 For this I have to input co-ordinates in the form of [[x1 y1] [x2 y2] [x3 y3];[x4 y4] [x5 y5] [x6 y6]]. 为此,我必须以[[x1 y1] [x2 y2] [x3 y3]; [x4 y4] [x5 y5] [x6 y6]]的形式输入坐标。 I have tried using cell array but arithmetical operations with other matrices or array isn't possible while using cell array. 我已经尝试过使用单元格数组,但是在使用单元格数组时无法对其他矩阵或数组进行算术运算。 Please help example: 请帮忙举例:

C=[[2 3] [3 4] [4 5] [5 6];[2 5] [5 2] [7 8] [8 9]];
A=C(1,3);
ans=[4 5]

Also

C=[[2 3] [3 4] [4 5] [5 6];[2 5] [5 2] [7 8] [8 9]];
D=[1 2;2 1;3 1;2 3];
E=C*D
ans=[[30 38] [26 33];[49 51] [40 47]]

you can try using cat(3,..) : 您可以尝试使用cat(3,..)

C = cat(3,[[2 3] ;[3 4] ;[4 5]; [5 6]],[[2 5]; [5 2] ;[7 8] ;[8 9]]);
A = C(3,:,1)

You could use a 3D matrix, with the second "layer" being your second coordinate pair, or simply use 2 matrices! 您可以使用3D矩阵,其中第二个“层”是第二个坐标对,或者仅使用2个矩阵!

Using your example: 使用您的示例:

C1 = [2 3 4 5; 2 5 7 8];
C2 = [3 4 5 6; 5 2 8 9];
D = [1 2; 2 1; 3 1; 2 3];
E1 = C1*D; E2 = C2*D;

In 3D matrices: 在3D矩阵中:

% Make 3D matrix of same size as C1 but 2 layers
C = zeros([size(C1), 2]);
C(:,:,1) = C1; C(:,:,2) = C2;
E = cat(3, C(:,:,1)*D, C(:,:,2)*D);
% ans is a 3D matrix, with the 2 layers representing the pairs in your example.

Indexing the 3D matrix like you wanted: 像想要的那样索引3D矩阵:

C13 = reshape(C(1,3,:),1,2) % C13 = [4, 5] 
% or
C13 = squeeze(C(1,3,:))'    % C13 = [4, 5]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM