在 MATLAB 中绘制图形

发布于 2024-08-14 11:53:28 字数 191 浏览 4 评论 0原文

我有一个 txt 文件,每行包含以下值:

SRNO  Value1  Value2

大约有 2000 个这样的行。

我想在 MATLAB 中绘制 Value1Value2

关于如何做到这一点的代码吗?谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

油焖大侠 2024-08-21 11:53:28

一个简单的 load 然后 plot 就可以做到:

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

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
罪#恶を代价 2024-08-21 11:53:28

绘图很简单:

plot(xvec,yvec)

您遇到的真正问题是尝试将值读入程序中。查看帮助文档中的csvreader函数或文件读取。 csvread() 帮助文档看起来需要一个真正的逗号分隔值文件,但帮助 dox 链接到 textscan() 看起来更好:

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

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

坏尐絯℡ 2024-08-21 11:53:28

尝试这样的操作:

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

%*s 应该删除文本并留下 x,y 值。不确定这是否是您想要做的,但请查看 plottextscan 了解更多信息。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文