Help reading data from an input file, then plotting it!

14 views (last 30 days)
I have already submitted this question, however I accidentally accepted the answer even though the given solution didn't work.
the responder to my previous question told me to say
y = atmospheretable(:,1);
instead of
y = filename(:,1);
This did not solve my problem. I have the variable 'filename' there so that any file can be read by this script, not just ones named 'atmospheretable'.
Any help would be greatly appreciated!
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(x,y);
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!

Accepted Answer

Jonathan
Jonathan on 30 Jan 2011
I figured it out!
I changed:
load(filename);
x = filename(:,1);
y = filename(:,3);
to:
atmospheretable = load(filename);
x = atmospheretable(:,1);
y = atmospheretable(:,3);
Thanks!

More Answers (0)

Community Treasure Hunt

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

Start Hunting!