필터 지우기
필터 지우기

Drawing a segment of a cylinder from a matrix

조회 수: 3 (최근 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)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by