필터 지우기
필터 지우기

How to pass the name of a file to a function - dataset

조회 수: 1 (최근 30일)
Diego
Diego 2012년 12월 7일
Dear all,
How can I create a function for loading an excel file into a dataset array in matlab?
I have tried something like this:
function tryB( X )
data=dataset('xlsfile',inputname(1));
end
But I get the following error each time.
Undefined function 'tryB' for input arguments of type 'char'.
Thank you,
Diego

채택된 답변

Sean de Wolski
Sean de Wolski 2012년 12월 7일
Two things:
1) Apparently the file tryB.m is not saved on your ML path. Add the folder it's in to the path
2) inputname will use the name of the variable passed in, not it's value. So instead call tryB with the filename and use X
tryB('test1.xlx')
And inside of tryB:
data=dataset('xlsfile',X);
doc function %for more information

추가 답변 (1개)

Diego
Diego 2012년 12월 7일
Thank you Sean.
Regards,
Diego

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by