function acts differently in command window to when its run in a .m file.

Hello, so I'm having this problem with the exist command.
I have a program PlotDep.m which uses a function getFileName.m to get a file name, next I check to see if the filename exists which works and that works fine. I want to run PlotDep.m several times over so I turned it into a function and created a new program to run and get a batch of plots, this file is called covarianceBatch.m.
When I run the covarianceBatch.m it is supposed to run the
PlotDep(mode(a), sampleTime(b), model(c), height(d))
function over and over again but I get the error
Undefined function or method 'exist' for input arguments of type 'cell'
end
which corresponds to the lines of code in PlotDep.m
filename = getFileName(radar, sYear, sMonth, sDay, model);
if exist(filename, 'file');
if i run
PlotDep(mode(a), sampleTime(b), model(c), height(d))
in the command window it works fine? Any idea why this could be?

댓글 수: 1

Star Strider
Star Strider 2012년 7월 28일
편집: Star Strider 2012년 7월 28일
I suggest you explore the documentation for the ‘which’ function: http://www.mathworks.com/help/techdoc/ref/which.html. It may provide you with the information you want.
If your ‘PlotDep.m’ file isn't too long, please post all of it.
I can't find any information on the ‘getFileName’ function. If you wrote it, you need to post the code for it as well.

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

답변 (3개)

Wayne King
Wayne King 2012년 7월 28일
편집: Wayne King 2012년 7월 28일
What is getFileName returning? We need to know what that looks like
For example, if you run it from the command line
>>filename = getFileName(radar, sYear, sMonth, sDay, model);
>> whos filename
returns what?
Depending on what that returns, you may be able to fix your code with
if exist(char(filename), 'file')
Oleg Komarov
Oleg Komarov 2012년 7월 28일
편집: Oleg Komarov 2012년 7월 28일

0 개 추천

As the error message suggests, one of the inputs to the exist function is probably a cell type.
In the cmd window type
dbstop if error
then run the covarianceBatch and check the inputs once it errors.
Finally,
dbclear if error
to reset.
Star Strider
Star Strider 2012년 7월 28일

0 개 추천

I suggest you explore the documentation for the ‘which’ function: http://www.mathworks.com/help/techdoc/ref/which.html. It may provide you with the information you want.
If your ‘PlotDep.m’ file isn't too long, please post all of it.
I can't find any information on the ‘getFileName’ function. If you wrote it, you need to post the code for it as well.

카테고리

도움말 센터File Exchange에서 Debugging and Analysis에 대해 자세히 알아보기

질문:

2012년 7월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by