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
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
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
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
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 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!