MATLAB: Trouble reading an input file and plotting the file’s data

read; file; plot; data

Hello,
I am attempting to read an input file, and plot the file's data. At first glance, my question seems like a simple fix… however it really isn't that easy.
I started off with the following code:
clear,clc;
load atmospheretable.dat
y = atmospheretable(:,1); x = atmospheretable(:,3);
plot(x,y);
xlabel('temperature'); ylabel('altitude');
title('temperature vs. altitude')
which is a very straight-forward way to read a file and plot the data. This method worked perfectly. However, I do not think that a filename should ever be hard-wired into code, so I modified the code to allow the user to select a file. My code became as such:
clear, clc;
filename = uigetfile('*.*', 'Select File');
load(filename);
y = filename(:,1); x = filename(:,3);
plot(y,x);
xlabel('temperature'); ylabel('altitude');
title('temperature vs altitude');
I subsequently get: ??? Error using ==> plot Invalid first data argument
Error in ==> atmosphereplot at 24 plot(y,x);
I have no idea why i am getting this error! This should work! Could somebody explain to me what I'm doing wrong here? I've been going at this for three hours now with no resolution!
Thank you!

Best Answer

Do the same thing in second code
y = atmospheretable(:,1); x = atmospheretable(:,3);
instead of y = filename(:,1); x = filename(:,3);
Here's a small tip, always keep the little Workspace window with all variables listed in your matlab, you wouldn't waste your time with such small problems.