Data Reshape for Contour Plot

7 次查看(过去 30 天)
Hello,
I'm facing a few problems while data reshaping. I have velocity values in a cartesian coordinate system (x,y,z) . The values are at the surface of a cylinder with a defined radius.
Therefore a transformation into cylinder coordinates to plot the data as 2D contour (Angle and Height) is suitable.
My Problem is that I have all the necessary data in the file 'TransformedData.txt' but it is not the required format for contourf.
I tried to reshape the data inspired by this post: (https://de.mathworks.com/matlabcentral/answers/421043-contour-plot-based-on-xyz-data) but it's still not working.
clc,close all
clearvars
filename='RawDataCFXPost.xlsx';
% Data Transformation
x=xlsread(filename,'A3:A36003');% Cartesian Coordinate x
y=xlsread(filename,'B3:B36003');% Cartesian Coordinate y
z=xlsread(filename,'C3:C36003');% Cartesian Coordinate z
ZData=xlsread(filename,'D3:D36003');% Velocity Value v
[theta,rho,z] = cart2pol(x,y,z);% Coordinate Transformation from Cartesian to Clyinder Coordinate System
A=[theta,rho,z,ZData];% Array with Transformed Data
writematrix(A,'TransformedData.txt','Delimiter',' ');
type TransformedData.txt;
% Data Reshape
Data = load('TransformedData.txt');
[Du,D1] = unique(Data(:,1));
Dd = diff(D1);
DataNew = reshape(Data, Dd(1), [], size(Data,2));
Angle = DataNew(:,:,1);
Height = DataNew(:,:,3);
Velocity = DataNew(:,:,4);
% Contour Plot
figure
contourf(Angle, Height, Velocity)
Maybe someone has a clue to solve this issue.
With best regards
Steffen

采纳的回答

KSSV
KSSV 2024-9-20
T = readtable('https://in.mathworks.com/matlabcentral/answers/uploaded_files/1776380/RawDataCFXPost.xlsx');
[theta,rho,z] = cart2pol(T.(1),T.(2),T.(3));
x = linspace(min(theta),max(theta),500) ;
y = linspace(min(rho),max(rho),500) ;
z = T.(4) ;
[X,Y] = meshgrid(x,y) ;
Z = griddata(theta,rho,z,X,Y) ;
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
contourf(X,Y,Z)
  3 个评论
Steffen B.
Steffen B. 2024-9-20
Hello KSSV,
thankls for your answer. I did a few adaptions and now it's working just fine.
Thanks for your help.
KSSV
KSSV 2024-9-20
That's great...cheers :)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Contour Plots 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by