필터 지우기
필터 지우기

Creating a matrix for each point point in a data set

조회 수: 1 (최근 30일)
Jeff C.
Jeff C. 2015년 2월 21일
댓글: Sad Grad Student 2015년 2월 21일
I am trying to create a new matrix for each point in a large dataset, but I am not sure how I can do this without writing out each one. From this dataset I have created an origin and three vectors for each point, and I need to put the origin and three vectors into a 4x4 identity matrix. Is there a way to do this using for loops?
  댓글 수: 2
Sad Grad Student
Sad Grad Student 2015년 2월 21일
Can you give an example of what you want?
Jeff C.
Jeff C. 2015년 2월 21일
So I have a data set of 806 points and I have created 806 origins, x vectors, y vectors, and z vectors. I need a 4x4 matrix that would look like (1,0,0,0;o1,x1,x2,x3;o2,y1,y2,y3;o3,z1,z2,z3) for each of the 806 data points. I hope that helps.

댓글을 달려면 로그인하십시오.

채택된 답변

Sad Grad Student
Sad Grad Student 2015년 2월 21일
M = {}; % creating a cell array that will contain your 806 matrices
for i = 1:806
M{i} = eye(4,4);
M{i}(2:end,1) = o; % your vector of origins. o = [o1 o2 o3]
M{i}(2:end,2) = x; % your x vector. x = [x1 x2 x3]
M{i}(2:end,3) = y; % your y vector. y = [y1 y2 y3]
M{i}(2:end,4) = z; % your z vector. z = [z1 z2 z3]
end
  댓글 수: 2
Jeff C.
Jeff C. 2015년 2월 21일
I tried this but it told me there was an error with dimension size, so I changed it to: for i = 1:806 M{i} = eye(4,4); M{i}(2:end,1) = o(i,:); % your vector of origins. o = [o1 o2 o3] M{i}(2:end,2) = x(i,:); % your x vector. x = [x1 x2 x3] M{i}(2:end,3) = y(i,:); % your y vector. y = [y1 y2 y3] M{i}(2:end,4) = z(i,:); % your z vector. z = [z1 z2 z3] end
The code runs without error now, however if I try to call the 200th matrix, using a=M(200) it just returns a=[4x4 double]. Not sure what is wrong there.
Thanks so much for your help by the way.
Sad Grad Student
Sad Grad Student 2015년 2월 21일
For cell, you need to ask for M{200}.. curly brackets instead of round.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by