Data Reshape for Contour Plot

3 ビュー (過去 30 日間)
Steffen B.
Steffen B. 2024 年 9 月 20 日
コメント済み: KSSV 2024 年 9 月 20 日
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 Center および File ExchangeContour Plots についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by