MATLAB Answers

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

2 views (last 30 days)
Jason Baxter
Jason Baxter on 28 Jul 2012
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 Comment

Star Strider
Star Strider on 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.

Sign in to comment.

Answers (3)

Wayne King
Wayne King on 28 Jul 2012
Edited: Wayne King on 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')

  0 Comments

Sign in to comment.


Oleg Komarov
Oleg Komarov on 28 Jul 2012
Edited: Oleg Komarov on 28 Jul 2012
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.

  0 Comments

Sign in to comment.


Star Strider
Star Strider on 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.

  0 Comments

Sign in to comment.

Sign in to answer this question.