views:

150

answers:

2

I created a GUI and used uiimport to import a dataset into matlab workspace, I would like to pass this imported data to another function in matlab...How do I pass this imported dataset into another function....I tried doing diz...but it couldnt pick diz....it doesnt pick the data on the matlab workspace....any ideas??

[file_input, pathname] = uigetfile( ...
{'*.txt', 'Text (*.txt)'; ...
'*.xls', 'Excel (*.xls)'; ...
'*.*', 'All Files (*.*)'}, ...
'Select files');

uiimport(file_input);
M = dlmread(file_input);
X = freed(M);
+1  A: 

I think that you need to assign the result of this statement:

uiimport(file_input);

to a variable, like this

dataset = uiimport(file_input);

and then pass that to your next function:

M = dlmread(dataset);

This is a very basic feature of Matlab, which suggests to me that you would find it valuable to read some of the on-line help and some of the documentation for Matlab. When you've done that you'll probably find neater and quicker ways of doing this.

EDIT: Well, @Tim, if all else fails RTFM. So I did, and my previous answer is incorrect. What you need to pass to dlmread is the name of the file to read. So, you either use uiimport or dlmread to read the file, but not both. Which one you use depends on what you are trying to do and on the format of the input file. So, go RTFM and I'll do the same. If you are still having trouble, update your question and provide details of the contents of the file.

High Performance Mark
The Matlab documentation is very well written, and should really help make things clear. If you don't want to read, you can also watch one of the many video tutorials, like this one: http://www.mathworks.com/support/2010a/matlab/7.10/demos/WritingAMATLABProgram.html
Jonas
....i tried dat already....got some errors!!!
Tim
??? Error using ==> dlmread at 55Filename must be a string.Datz what i got wen i tried using dlmread
Tim
A: 

In your script you have three ways to read the file. Choose one on them depending on your file format. But first I would combine file name with the path:

file_input = fullfile(pathname,file_input);

I wouldn't use UIIMPORT in a script, since user can change way to read the data, and variable name depends on file name and user.

With DLMREAD you can only read numerical data from the file. You can also skip some number of rows or columns with

M = dlmread(file_input,'\t',1,1);

skipping the first row and one column on the left. Or you can define a range in kind of Excel style. See the DLMREAD documentation for more details.

The filename you pass to DLMREAD must be a string. Don't pass a file handle or any data. You will get "Filename must be a string", if it's not a string. Easy.

FREAD reads data from a binary file. See the documentation if you really have to do it.

There are many other functions to read the data from file. If you still have problems, show us an example of your file format, so we can suggest the best way to read it.

yuk