How to display a matrix with many NaN-values?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
I have many values of a 2D field and their corresponding coordinaes in a given x-y-range. Yet the coordinates do not form a uniformly occupied grid, it is more like a sparse matrix, the x and y values are often unique and partially only conain one single value per column/line.
Nevertheless, I want to plot my data and interpolate over the NaN entries but the common functions like pcolor and colormap only return a blank figure (except from the denser occupied edges as you can see in the figure).
How do I recieve a interpolated field?
data=file(:,1); %the data points
X=unique(file(:,2));
Y=unique(file(:,3)); %the x and y-coordinates
Field=NaN(length(X),length(Y)); %creates an empty grid
for j=1:length(data)
Xj=find(X==file(j,2));
Yj=find(Y==file(j,3));
Field(Xj,Yj)=data(j); %fills in the known values
end
figure()
pcolor(Field); shading interp;

2 commentaires
Jan
le 26 Avr 2022
You want to interpolate over the rectangular grid. This is a good idea. As you can see, pcolor does not do what you want to without this interpolation.
The conversion would be faster with:
X = file(:, 2);
Y = file(:, 3);
Field = NaN(max(Y), max(X));
Field(sub2ind(size(Field), Y, X)) = file(:, 1);
Réponses (1)
Timo Conrad
le 26 Avr 2022
3 commentaires
Akira Agata
le 28 Avr 2022
Ah, it's a Karman vortex, isn't it?
Thank you for sharing the data. The following is a simple example:
load('file.mat');
x = file(:,2);
y = file(:,3);
z = file(:,1);
[xg, yg] = meshgrid(...
linspace(min(x), max(x)),...
linspace(min(y), max(y)));
F = scatteredInterpolant(x, y, z, 'natural');
zg = F(xg, yg);
figure
surf(xg,yg,zg,...
'EdgeColor','none')
view(2)
daspect([1 1 1])
box on
colorbar('southoutside')

Voir également
Catégories
En savoir plus sur Color and Styling dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
