Data Reshape for Contour Plot

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