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 Kommentar

Star Strider
Star Strider am 28 Jul. 2012
Bearbeitet: Star Strider am 28 Jul. 2012
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.

Melden Sie sich an, um zu kommentieren.

Antworten (3)

Wayne King
Wayne King am 28 Jul. 2012
Bearbeitet: Wayne King am 28 Jul. 2012
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 am 28 Jul. 2012
Bearbeitet: Oleg Komarov am 28 Jul. 2012

0 Stimmen

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 am 28 Jul. 2012

0 Stimmen

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.

Kategorien

Mehr zu Debugging and Analysis finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 28 Jul. 2012

Community Treasure Hunt

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

Start Hunting!

Translated by