How to read a txt file in matlab?

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 comentarios

Image Analyst
Image Analyst el 30 de Ag. de 2018
Editada: Image Analyst el 30 de Ag. de 2018
Your attached data look nothing like either one of those. Just open it in Notepad to see. It looks like this:
81.4724
90.5792
12.6987
91.3376
63.2359
9.7540
27.8498
54.6882
EcoBase
EcoBase el 30 de Ag. de 2018
Editada: Stephen23 el 30 de Ag. de 2018
Oops!! I'm so sorry, I attached a wrong one. Please check the new file attached. (The file is too large, so I pasted only a few rows from the original one). What I'm trying to do is the same as this approach - https://kr.mathworks.com/matlabcentral/answers/337686-how-to-create-an-image-from-txt-file
The file contains x, y coordinates of an image and relevant value for each pixel. Thank you.
EcoBase
EcoBase el 31 de Ag. de 2018
I uploaded two original files and shared in links below: https://drive.google.com/open?id=1utfXBqnRgjv6AIl_dSor-amooxk3-QwQ
https://drive.google.com/open?id=12NGdhO6xZ1525IkjLUhIHEKjSxbgGy1o
I'd really appreciate it if you could check and help me with the problem! Thank you.

Iniciar sesión para comentar.

 Respuesta aceptada

KSSV
KSSV el 30 de Ag. de 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 comentarios

EcoBase
EcoBase el 30 de Ag. de 2018
Thank you for your answer! I really appreciate your time commitment for this dumb question :-) I tried, but I see the same problem again. When I imported the data, the data matrix is shown like, for example, (0.7560, 0.2600, 0.0011), but it should be something like this, (756, 260, 0.00115986). I don't know if I just have to ignore this! Also, I got an error with 'scatteredInterpolant'.
KSSV
KSSV el 30 de Ag. de 2018
What error? Attach your whole file...If size is big...attach in drive and paste link here.
EcoBase
EcoBase el 30 de Ag. de 2018
It says 'scatteredInterpolant' isn't a valid extrapolation type. Here are links for the file in two different format (text and excel). Thank you so much.
https://drive.google.com/open?id=1utfXBqnRgjv6AIl_dSor-amooxk3-QwQ
https://drive.google.com/open?id=12NGdhO6xZ1525IkjLUhIHEKjSxbgGy1o
EcoBase
EcoBase el 31 de Ag. de 2018
Could decimals in Z axis matter? When I tried with other files containing only integers, it seemed to be working okay. I could produce an image in the way I wanted.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

el 30 de Ag. de 2018

Comentada:

el 31 de Ag. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by