필터 지우기
필터 지우기

Importdata within a User-Defined Matlab Function

조회 수: 3 (최근 30일)
Linford Briant
Linford Briant 2012년 3월 10일
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!
  댓글 수: 1
Oleg Komarov
Oleg Komarov 2012년 3월 10일
http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer
It doesn't work says nothing about your problem, please post the error message and more code.

댓글을 달려면 로그인하십시오.

채택된 답변

Ken Atwell
Ken Atwell 2012년 3월 10일
You are passing mydata to importdata as a string literal (single quotes around the word mydata), so MATLAB is trying to open a file called "mydata", when you intend to load what is specified by the value of the variable mydata.
Remove the single quotes and you should be in good shape:
M=importdata(mydata,1,' ')

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT-Files에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by