How to get and 3D matrix from 2 2D matirces?

조회 수: 1 (최근 30일)
Paramveer Singh GopalSingh
Paramveer Singh GopalSingh 2022년 5월 30일
답변: Hiro Yoshino 2022년 5월 30일
Hi I have 2 structures(of many cells) that plot the 2d coordinates of a particle in XY coordinates and YZ cordinates and I want to create a structre that gives me the 3D coordinate from them by matching the points in at the Y plane? Any idea how to approach this issue?
  댓글 수: 2
Sam Chak
Sam Chak 2022년 5월 30일
Can you provide two samples of the 2D matrices?
Matt J
Matt J 2022년 5월 30일
편집: Matt J 2022년 5월 30일
To prevent confusion, avoid terminology like "structure" and "cell" which refer to specific Matlab data types,
unless they are truly what you are using.

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

답변 (1개)

Hiro Yoshino
Hiro Yoshino 2022년 5월 30일
How about the following solution using "ismember" ?
% xy - 2D matrix
x = [1 2 3 4 5]';
y1 = [3 2 1 4 5]';
xy = [x,y1]
xy = 5×2
1 3 2 2 3 1 4 4 5 5
%yz - 2D matrix
y2 = [1 2 3 4 5]';
z = [10 15 3 4 9]';
yz = [y2,z]
yz = 5×2
1 10 2 15 3 3 4 4 5 9
% correspondance:
[idx, loc]=ismember(y1,y2);
% check if y1 and y2(loc) are identical
y1
y1 = 5×1
3 2 1 4 5
y2(loc)
ans = 5×1
3 2 1 4 5
% 3D matrix
xyz = [x,y1,z(loc)]
xyz = 5×3
1 3 3 2 2 15 3 1 10 4 4 4 5 5 9

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by