MATLAB - 加载文件,其文件名存储在字符串中

Mar*_*ark 9 string matlab-load

我正在使用MATLAB处理文件中的数据.我正在编写一个程序,它从用户那里获取输入,然后将特定文件定位在绘制它们的目录中.文件命名为:

{名} U {}率

{name}是表示计算机名称的字符串.{rate}是一个数字.这是我的代码:

%# get user to input name and rate
NET_NAME = input('Enter the NET_NAME of the files: ', 's');
rate = input('Enter the rate of the files: ');

U = strcat(NET_NAME, 'U', rate)
load U;

Ux = U(:,1);
Uy = U(:,2);
Run Code Online (Sandbox Code Playgroud)

目前有两个问题:

  1. 当我strcat说"你好","你好",费率是50时,你会存储'helloU2' - 我怎样才能strcat正确追加{rate}?

  2. 加载线 - 如何取消引用U,以便加载尝试加载存储在U中的字符串?

非常感谢!

Amr*_*mro 8

米哈伊尔上面的评论解决了你的直接问题.

用户友好的选择文件的方式:

[fileName,filePath] = uigetfile('*', 'Select data file', '.');
if filePath==0, error('None selected!'); end
U = load( fullfile(filePath,fileName) );
Run Code Online (Sandbox Code Playgroud)