开发者

Plot graphs in MATLAB

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


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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜