Tuesday 15 March 2011

matlab - 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 The files in the file are .mat files and are loaded with

load ("filename.mat")

I am about to do something like Thinking:

This is possible because you need to input the file name enclosed in single quotation marks: ' Filename '(Note: I use MATLAB but it should work only in Octave.)

As an alternative, You can use inputdlg to request the output. This gives you a lot of flexibility because you can add fields to file extensions or other such signals.

Here's 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 get asnwer like this:

  name = answer {1};  

And finally add the extension to load the .mat file:

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

To do this from file extension in one:

  prompt = {'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}; File name = difference (name, expansion) s = load (file name)  

Hope that helps!


No comments:

Post a Comment