Issues plotting R,theta, T from X,Y,Z data
Afficher commentaires plus anciens
Hello everyone!
I have data of a cylinder with certain tempretures at each point and the data is unfortunatley in X,Y,Z coordinates (as if the cylinder is floating in a cartesian system). I wrote code that transforms th data to R, theta coordinates as well as pick the outer and inner radii and plot them on a 2d plane (theta vs X with T colour map). The problem I have is that the data from around 0-0.6 radians is messed up with either missing or wrong points plotted. I do use a tolerance for matlab to check if the point being checked is outer or inner but increasing the tolerance anymore makes the graph intefer with inner layers. Here is the code below:
clc;
clear;
coords = readtable("Al_Case1.xlsx");
coords = table2array(coords);
X = coords(:,1);
Y = abs(coords(:,2));
Z = coords(:,3);
T = coords(:,4);
Z_center = mean(Z);
Y_center = mean(Y);
R = ((Z-Z_center).^2 + (Y-Y_center).^2).^0.5;
Theta = atan2(Z-Z_center, Y-Y_center);
itt = 0;
itti = 0;
Ro = max(R);
Ri = min(R);
for i = 1:length(R)
if Theta(i) < 0
Theta(i) = Theta(i)+pi;
end
if Ro-R(i) <= 0.25 || R(i) > Ro
if itt >= 1 && ismember(Theta(i),Thetao) && X(i) == thicknesso(ismember(Theta(i),Thetao))
io = ismember(Theta(i),Thetao);
if R(i) > Router(io)
Router(i) = R(i);
To(i) = T(i);
thicknesso(i) = X(i);
Thetao(i) = Theta(i);
itt = itt+1;
end
else
Router(i) = R(i);
To(i) = T(i);
thicknesso(i) = X(i);
Thetao(i) = Theta(i);
itt = itt+1;
end
end
if R(i)-Ri <= 0.25 || R(i) < Ri
if itti >= 1 && ismember(Theta(i),Thetai) && X(i) ==thicknessi(ismember(Theta(i),Thetai))
ii = ismember(Theta(i),Thetai);
if R(i) < Rinner(ii)
Rinner(i) = R(i);
Ti(i) = T(i);
thicknessi(i) = X(i)-300;
Thetai(i) = Theta(i);
itti = itti+1;
end
else
Rinner(i) = R(i);
Ti(i) = T(i);
thicknessi(i) = X(i)-300;
Thetai(i) = Theta(i);
itti = itti+1;
end
end
end
valid_outer = Router ~= 0;
Router = Router(valid_outer);
To = To(valid_outer);
Thetao = Thetao(valid_outer);
thicknesso = thicknesso(valid_outer);
valid_inner = Rinner ~= 0;
Rinner = Rinner(valid_inner);
Ti = Ti(valid_inner);
Thetai = Thetai(valid_inner);
thicknessi = thicknessi(valid_inner);
[Thetao, idx_o] = sort(Thetao, 'descend');
thicknesso = thicknesso(idx_o);
Router = Router(idx_o);
To = To(idx_o);
Thetao = Thetao *360/pi;
[Thetai, idx_i] = sort(Thetai, 'descend');
thicknessi = thicknessi(idx_i);
Rinner = Rinner(idx_i);
Ti = Ti(idx_i);
Thetai = Thetai *360/pi;
scatter(Thetao,thicknesso,20,To,"filled")
hold on
scatter(Thetai,thicknessi,20,Ti,"filled")
colorbar;
title('Cylinder Temperature');
grid on;
hold off
I tried with some i statments to make it check if the point was already plotted and if it was to pick the point that is outermost (for plotting the outter surface) and innermost (for inner surface) but that didn't seem to change much.
Any clue or way I could go to fix it would be greatly appreciated thanks!
6 commentaires
Ahmed
le 12 Fév 2025
Mathieu NOE
le 12 Fév 2025
hello
seems I have to ask every time - please share the data that goes with the code.... otherwise we're not in position to help efficiently -
Star Strider
le 12 Fév 2025
Ahmed
le 12 Fév 2025
Ahmed
le 12 Fév 2025
Mathieu NOE
le 12 Fév 2025
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur 2-D and 3-D Plots dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





