Am I using slice incorrectly?

19 ビュー (過去 30 日間)
Nicholas Kreitinger
Nicholas Kreitinger 2016 年 2 月 17 日
コメント済み: Walter Roberson 2016 年 2 月 17 日
I'm plotting an n x 3 matrix which has temperature data, each of the indexes corresponds to location T(x,y,z). My problem is when I use slice it switches the x and y planes. The array is still stored correctly when points are called and the slices are in the right planes but instead of x extending to 72 it only goes to 24. I'm using Matlab 2012b if that makes any difference.
clear; clc;
T=ones(72,24,72);
T(50:60, :, :)=100;
T(:, 18:22, :)=-25;
figure; h= slice(T,[],[], 1);
for id = 1:72
delete(h);
h= slice(T,[],[], id);
set(h,'edgecolor','none');
axis([0 72 0 24 0 72]);
xlabel(' X axis');
ylabel(' Y axis');
zlabel(' Z axis');
colorbar;
pause(0.01);
end

採用された回答

Walter Roberson
Walter Roberson 2016 年 2 月 17 日
Notice from the documentation for slice:
slice(V,sx,sy,sz) draws slices along the x, y, z directions in the volume V at the points in the vectors sx, sy, and sz. V is an m-by-n-by-p volume array containing data values at the default location X = 1:n, Y = 1:m, Z = 1:p. Each element in the vectors sx, sy, and sz defines a slice plane in the x-, y-, or z-axis direction.
Your volume is m-by-n-by-p, 72-by-24-by-72 so m=72. n=24, p=72, and so X = 1:24, Y = 1:72, Z = 1:72 which is what you are observing.
In other words, when you plot, X is columns (second index) and Y is rows (first index)
  2 件のコメント
Nicholas Kreitinger
Nicholas Kreitinger 2016 年 2 月 17 日
Thanks, that answers my question although it really messes up the organization. Why would you change the function to Y,X,Z when everything else is X,Y,Z?
Walter Roberson
Walter Roberson 2016 年 2 月 17 日
Nothing (that I can think of) in MATLAB graphics uses X as the rows. For example if you image() an array, the rows determine the vertical values, which is the Y coordinate, and the columns determine the horizontal values, which is the X coordinate. MATLAB arrays are defined in terms of the first coordinate being "down".

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLighting, Transparency, and Shading についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by