简体   繁体   English

倍频程:负载问题

[英]Octave: Problems with load

I'm currently doing a program in Octave where I want the user to be able to insert the file that he wants to load. 我目前正在Octave中做一个程序,希望用户能够插入他要加载的文件。 The files in question are .mat files and are loaded with 有问题的文件是.mat文件,并与

load ("filename.mat") 加载(“ filename.mat”)

I was thinking about doing something like this: 我正在考虑做这样的事情:

file=input("Whats the file name: ") file = input(“文件名是什么:”)

load ("file") 加载(“文件”)

But that didn't work... 但这没用...

Anyone got any tips? 有人提示吗?

That's likely because you need to input the file name enclosed in single quotation marks : 'filename'. 可能是因为您需要输入用单引号引起来的文件名:'filename'。 (Note: I use MATLAB but that should work just the same in Octave). (注意:我使用MATLAB,但在Octave中应该可以正常使用)。

As an alternative you can use inputdlg to request user input. 或者,您可以使用inputdlg请求用户输入。 It gives you much flexibility as you can add fields to the prompt such as the file extension or else. 它可以为您提供很大的灵活性,因为您可以在提示中添加字段,例如文件扩展名或其他。

Here is a simple example: 这是一个简单的示例:

clear
clc


prompt = {'Enter file name'};
dlg_title = 'Input';
num_lines = 1;
def = {'Dummy file'};
answer = inputdlg(prompt,dlg_title,num_lines,def)

The prompt looks like this: 提示如下:

在此处输入图片说明

You can fetch the asnwer like so: 您可以像这样获取请求:

name = answer{1};

And finally add the extension to load the .mat file: 最后添加扩展名以加载.mat文件:

filename = strcat(name,'.mat')
S = load(filename)

To do it in one go with the file extension: 只需使用文件扩展名即可:

prompt = {'Enter file name'; 'Enter file extension'};
dlg_title = 'Input';
num_lines = 1;
def = {'Dummy file'; '.mat'};
answer = inputdlg(prompt,dlg_title,num_lines,def)

name = answer{1};
extension = answer{2};

filename = strcat(name,extension)
S = load(filename)

Hope that helps! 希望有帮助!

I used Benoit_11's method but changed it to input instead since inputdlg doesn't seem to work in Octave. 我使用了Benoit_11的方法,但是将其更改为input,因为inputdlg似乎在Octave中不起作用。

clear 明确

clc c

name=input('Enter the file name, without the file extension: ','s') name = input('输入文件名,不带文件扩展名:','s')

filename = strcat(name,'.mat') 文件名= strcat(name,'。mat')

S = load(filename) S =负载(文件名)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM