ode45 function error using exist

조회 수: 2 (최근 30일)
Kyriacos Patsalides
Kyriacos Patsalides 2017년 1월 25일
댓글: Walter Roberson 2020년 4월 13일
I am running my code and when i call ode45 I get an error as followed:
Error using exist The first input to exist must be a string.
Error in odearguments (line 60) if (exist(ode)==2)
Error in ode45 (line 114) [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
What does it mean that the first input to exist must be a string?
  댓글 수: 1
Jan
Jan 2017년 1월 25일
Please post the complete error message and the command line, which calls ODE45. Thanks.

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

답변 (3개)

Torsten
Torsten 2017년 1월 25일
My guess is that the variable "ode" is not a string.
Best wishes
Torsten.

Jan
Jan 2017년 1월 25일
How do you call the integrator? What is the first input? It should be a function handle, but for backward compatibility functions can be provided as strings also.
  댓글 수: 1
Walter Roberson
Walter Roberson 2017년 1월 25일
I speculate that the poster might be using a very old version of MATLAB, such as MATLAB 5, where ode45 required a string instead of a handle.

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


Wan Nabilah
Wan Nabilah 2020년 4월 13일
편집: Walter Roberson 2020년 4월 13일
I am running my code and i get an error at if ~exist(fullFileName, 'file'). The error is
Error using exist
The first input to exist must be a string
scalar or character vector.
image_folder = 'C:\Users\User\Desktop\Image Pollen';
fullFileName = dir(fullfile(image_folder, '*.jpg'));
%filenames = dir(fullfile(image_folder, '*.jpg'));
% Get the full filename, with path prepended.
total_images = numel(fullFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = image_folder; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
Thank you!
  댓글 수: 2
Steven Lord
Steven Lord 2020년 4월 13일
When you call dir with an output argument, the contents of that output argument are not the names of the file or files that dir found. It is a struct array with one element per file found and a number of fields. exist doesn't expect its input to be a struct array.
If you want to check how many files dir found, ask for numel (NUMber of ELements) of that struct. If you want to check if dir found no files, you could instead ask if that output isempty.
Walter Roberson
Walter Roberson 2020년 4월 13일
dinfo = dir(fullfile(image_folder, '*.jpg'));
fullFileName = fullfile(image_folder, {dinfo.name});

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

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by