Data Reshape for Contour Plot

8 visualizzazioni (ultimi 30 giorni)
Steffen B.
Steffen B. il 20 Set 2024
Commentato: KSSV il 20 Set 2024
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

Risposta accettata

KSSV
KSSV il 20 Set 2024
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 Commenti
Steffen B.
Steffen B. il 20 Set 2024
Hello KSSV,
thankls for your answer. I did a few adaptions and now it's working just fine.
Thanks for your help.
KSSV
KSSV il 20 Set 2024
That's great...cheers :)

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Contour Plots in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by