0
我正在尝试创建一个脚本,要求用户输入一个txt文件的文件名,该文件的内容稍后将被绘制。加载存储在字符串中的文件名,然后绘制数据
filename = input('What is the filename (without the extension) e.g. RCP6: ','s');
if isempty(filename)
filename=input('What is the filename (without the extension) e.g. RCP6: ','s');
end
ext = input('What is the filetype (extension) e.g. .txt: ','s');
if isempty(ext)
ext=input('What is the filetype (extension) e.g. .txt: ','s');
end
filew = strcat(filename,ext)
load(filew)
A = filename
Y = A(:,1)
E = A(:,2)
plot(Y,E)
xlabel('calendar year')
ylabel('annual fossil carbon emissions (GtC)')
作为写入时,代码正确地连接的文件名和分机,然而,它不会出现负载(filew)正确地加载该文件中,由于给定的文件名=例如RCP3PD,Y = R和E = C ,而不是Y存储RCP3PD.txt中的第一列值?
有什么建议吗?我已经看到其他“从字符串加载文件”线程引用sprintf()函数 - 将在这里适用?
为什么在LOAD调用之后有'A = filename'?你的MAT文件里面还有什么?键入以下命令:'whos -file myFile.mat'来查看其内容 – Amro 2012-08-08 17:50:35
而不是在命令行上请求输入,请考虑使用像[UIGETFILE](http://www.mathworks.com/help/techdoc/)这样的函数REF/uigetfile.html)。有关示例,请参见[这里](http://stackoverflow.com/a/2304189/97160) – Amro 2012-08-08 17:55:34