Drawing a segment of a cylinder from a matrix

9 ビュー (過去 30 日間)
Yvotte Brits
Yvotte Brits 2017 年 9 月 6 日
コメント済み: Yvotte Brits 2017 年 9 月 14 日
Hi, I want to do a 3d plot of a 1/9th slice of a cylinder of the attached data points in Matlab. There is 51 layers in the z-direction, 36 points in the r direction and 9 points in the theta direction. Every coordinate have a value in matrix form that have to be indicated as a color in the 1/9th slice of the cylinder. What is the best way to draw this matrix in a 3d plot in Matlab?
Regards
Yvotte
  1 件のコメント
Stephen23
Stephen23 2017 年 9 月 13 日
編集済み: Stephen23 2017 年 9 月 13 日
Yvotte Brits' "Answer" moved here:
Hi I want to show the (r,theta,z) geometry of the sliced cylinder(1/9th sliced of the cylinder), and then the values flux as a color. So it is basically a 4d representation, with the r,theta and z being the coordinates of the sliced cylinder and then the values (flux) being represented as color etc.

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

採用された回答

Jocie Kluger
Jocie Kluger 2017 年 9 月 14 日
編集済み: Jocie Kluger 2017 年 9 月 14 日
The general idea is to reshape the z, r, and theta coordinates into 2D matrices of size (53*37) x 9 that correspond to the color data. Then, transform the r and theta coordinates into Cartesian coordinates. Transform all of the matrices into vectors so that they can be plotted with the scatter3 command, where you can specify each marker color. Please refer to the documentation for details on the command syntax.
%Read and format data
filename = '3d Fluxes.xls';
sheet= 1;
z= xlsread(filename,sheet,'A:A'); %get z data
z(isnan(z))= []; %remove NaN
r= xlsread(filename,sheet,'B:B'); %Get r data
r(isnan(r))= [];
theta= xlsread(filename,sheet,'C2:K2'); %Get theta data
ColorData= xlsread(filename,sheet,'C1:K2067');
%Remove extraneous rows. Not most efficient way
removeRowInds= 1; %first row to remove. Excel merge in row 2 affects this.
for i= 1:52
removeRowInds= [removeRowInds 39*i 1+39*i];
end
ColorData(removeRowInds,:)= [];
ColorVector= reshape(ColorData, numel(ColorData), 1);
%%Reformat data so all 1D vectors.
%Order to take data: 37*53 rows. Then reshape column-wise.
%zVector should repeat r times theta times then change value
zRow= z'; %turn z into row vector
zMat1= repmat(zRow, 37, 1);
zVector1= reshape(zMat1, numel(zMat1),1);
zMat= repmat(zVector1, 1,9); %z value for each ColorData value
zVector= reshape(zMat,numel(zMat), 1); %turn z back into a vector
rMat= repmat(r, 1, length(theta));
rVector= reshape(rMat, numel(rMat), 1);
thetaMat= repmat(theta, 37*53,1);
thetaVector= reshape(thetaMat, numel(thetaMat),1);
%Turn r and theta into matrices of X and Y
X= rVector.*cos(thetaVector);
Y= rVector.*sin(thetaVector);
%%Final plot
S = repmat(25,numel(X),1); %Specify marker size
scatter3(X,Y,zVector, S, ColorVector);% scatter3(X,Y,Z,S,C)
  1 件のコメント
Yvotte Brits
Yvotte Brits 2017 年 9 月 14 日
Thanks Jocie!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by