How to read a txt file in matlab?
237 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm completely new to Matlab, so my question may sound dumb! I apologize. I'm trying to open a txt file in Matlab and produce a colormap with the data in the file. But it seems like Matlab doesn't read the file correctly. I attached the file for your reference. I used 'importdata' function. It should look like

but every time I import the data, it shows something like this:

Can anyone please help me? Thank you so much in advance
3 commentaires
Réponse acceptée
KSSV
le 30 Août 2018
data = importdata('data.txt') ;
x = data(:,1) ; y = data(:,2) ; z = data(:,3) ;
plot3(x,y,z) ; % with the present data
% If you want a surf plot and data is full
% surf
N = 100 ;
xi = linspace(min(x),max(x),N) ;
yi = linspace(min(y),max(y),N) ;
[X,Y] = meshgrid(xi,yi) ;
F = scatteredInterpolant(x,y,z,'linear','none') ;
Z = reshape(F(X(:),Y(:)),N,N) ;
figure
pcolor(X,Y,Z)
4 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Type Identification 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!