views:

274

answers:

3

I have a txt file with the following values on each line:

SRNO  Value1  Value2

There are around 2000 such lines.

I would like to plot both Value1 and Value2 in MATLAB

Any code on how I could do it? Thanks

+1  A: 

Plotting is straightforward:

plot(xvec,yvec)

The real problem you have is trying to read the values into the program at all. Check out the csvreader functions or file reading in the help documentation. csvread() help docs looks like it requires a real comma separated values file, but the help dox link to textscan() which looks better:

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/textscan.html

Karl
+1  A: 

try something like this:

fid = fopen('scan1.txt');
C = textscan(fid, '%*s %f32 %f32');
fclose(fid);
plot(C);

The %*s should remove the text and leave you with x,y values. Not sure if that is what you are looking to do, but check out plot and textscan for more info.

David Glass
+5  A: 

A simple load then plot would do it:

data = load('file.txt');                            %# load file
plot(data(:,2), data(:,3), '.')                     %# plot value1 vs value2
xlabel('Value 1'), ylabel('Value 2'), title('Plot') %# add axes labels and title
Amro

related questions