MATLAB-加载文件名存储在字符串中的文件 [英] MATLAB - load file whose filename is stored in a string

查看:321
本文介绍了MATLAB-加载文件名存储在字符串中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

{name} U {rate}

{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);

当前存在两个问题:

  1. 当我用"hello","U"和"rate"为50来执行strcat时,U将存储"helloU2"-如何获得strcat正确附加{rate}?/p>

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

非常感谢!

解决方案

Mikhail的上述评论解决了您的直接问题.

一种更人性化的文件选择方式:

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

I am using MATLAB to process data from files. I am writing a program that takes input from the user and then locates the particular files in the directory graphing them. Files are named:

{name}U{rate}

{name} is a string representing the name of the computer. {rate} is a number. Here is my code:

%# 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);

There are currently two problems:

  1. When I do the strcat with say 'hello', 'U', and rate is 50, U will store 'helloU2' - how can I get strcat to append {rate} properly?

  2. The load line - how do I dereference U so load tries to load the string stored in U?

Many thanks!

解决方案

Mikhail's comment above solves your immediate problem.

A more user-friendly way of selecting a file:

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

这篇关于MATLAB-加载文件名存储在字符串中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆