## MATLAB: Importdata within a User-Defined Matlab Function

data importfunction

Hi Guys,

Suppose I have a function, called “myfun.m”, and I want, amongst other things, an input argument to this function to be a data file (.dat), how would I do this?

I have already defined all the code for the function, and it works, but now I want it to be able to apply it to any .dat file I choose, rather than just the dat file specified within the function it.

I currently use importdata, so the use of this within myfun.m, would be great.

`myfun(mydata,p1,p2,p3,...)`

Where myfun contains the line:

`M=importdata('mydata',1,' ')`

doesn’t work!

Any help would be much appreciated!

## Best Answer