フィルターのクリア

Z translate 3D matrix data

2 ビュー (過去 30 日間)
Brittney Gorman
Brittney Gorman 2020 年 7 月 9 日
コメント済み: Matt J 2020 年 7 月 10 日
I have a 3D matrix (512x512x600) full of data and a second 2D matrix that indicates the amount that each voxal needs to be translated by in the z-direction.
As a smaller example:
If I have 3D matrix M and want to translate each value in the (x,y) =(1,1) and (2,2) postion upward by one plane as defined by the values in matrix T= [1 0 0; 0 1 0; 0 0 0] while the rest of the points remain in the original planes
M = val(:,:,1) =
1 2 3
4 5 6
7 8 9
val(:,:,2) =
100 200 300
400 500 600
700 800 900
val(:,:,3) =
10 20 30
40 50 60
70 80 90
After translation I would want something that looked like this:
M = val(:,:,1) =
0 2 3
4 0 6
7 8 9
val(:,:,2) =
1 200 300
400 5 600
700 800 900
val(:,:,3) =
100 20 30
40 500 60
70 80 90
val(:,:,3) =
10 0 0
0 50 0
0 0 0

採用された回答

Matt J
Matt J 2020 年 7 月 9 日
編集済み: Matt J 2020 年 7 月 10 日
One way,
[m,n,p]=size(M);
[I,J,K]=ndgrid(1:m,1:n,1:p);
Knew=K+T;
result = accumarray([I(:),J(:),Knew(:)],M(:)),
  2 件のコメント
Brittney Gorman
Brittney Gorman 2020 年 7 月 10 日
I have attached the specific files. When I try to use this method I get the error message:
Error using accumarray
First input SUBS must contain positive integer subscripts.
Matt J
Matt J 2020 年 7 月 10 日
Your T matrix contains non-integer values, which your initial post does not discuss and which my code is not prepared to deal with. Perhaps modify your original example to show the outcome you expect of a non-integer translation. And what about negative translations? Do you have a definition for those?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Types についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by