Creating a Function

조회 수: 3 (최근 30일)
Brian
Brian 2011년 10월 31일
This may be a rather simple question for some but I am new to Matlab. I have written a function (in the process of automating a job) to use textscan to import some data prior to processing. I have a function that seems to work fine as a script, but for the function I've allowed the passing of a parm (FileName) so that I can go through and import multiple files. When I call the function it completes just fine, however there are no variables available in my workspace to be referenced for analysis. My Function is written as follows.
function ImportReturns2(MyFile)
%Create a connection to the file
FileToOpen = fopen(MyFile)
%Import the Returns Data using TextScan
MyData = textscan(FileToOpen, '%s %s %n','Delimiter',',')
%Close Connection to the File
fclose(FileToOpen)
end

채택된 답변

Jan
Jan 2011년 10월 31일
Add an output to the function header:
function MyData = ImportReturns2(MyFile)
Then call the function like:
MyData = ImportReturns2('FileName');
  댓글 수: 1
Brian
Brian 2011년 10월 31일
Thanks a lot for the quick response. I knew the solution would be easy.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by