【发布时间】:2012-08-05 21:34:18
【问题描述】:
我正在尝试创建一个脚本,该脚本会询问用户稍后将绘制其内容的 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)')
正如所写,代码正确连接了文件名和分机,但是,似乎 load (filew) 没有正确加载该文件,因为给定文件名 = RCP3PD,例如 Y = R 和 E = C,而不是 Y存储 RCP3PD.txt 中的第一列值?
有什么建议吗?我已经看到其他“从字符串加载文件”线程引用了 sprintf() 函数 - 这适用于这里吗?
【问题讨论】:
-
为什么在 LOAD 调用后有
A = filename?你的 MAT 文件里面还有什么?输入以下内容:whos -file myFile.mat以查看其内容