Drawing a segment of a cylinder from a matrix
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Yvotte Brits
il 6 Set 2017
Commentato: Yvotte Brits
il 14 Set 2017
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 Commento
Stephen23
il 13 Set 2017
Modificato: Stephen23
il 13 Set 2017
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.
Risposta accettata
Jocie Kluger
il 14 Set 2017
Modificato: Jocie Kluger
il 14 Set 2017
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)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Geographic Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!