Determining if a function exists seems harder than determining if a file exists, therefore I wouldn't expect it to compete in terms of speed. And if you have big cellstr arrays in there, convert them to char before saving if possible. To determine if a field exists at any other level, you can use either of the following methods. But you're not totally correct. Amro's method of splitting into separate variables will also let you selectively load parts of the struct; this one won't. Since you're on I:, I'm assuming that's a network drive, and you're probably running in to the dir contents caching problem that Jonas mentions.
I am using to check for the existence of a file on my machine. . Could simplify file management by keeping the data and index in a single file. So, if you are calling loadlibrary and you don't know why it takes forever - this question is also for you. And again the workaround is a standard good programming practize at all: never work with relative paths, but always use fully qualified path names - therefore I spend so much time in GetFullPath.
I think that that use case might be rare. What am I doing wrong? I am not able to use xlsinfo I think, this function is not available in the Matlab version I am currently using. A user of got problems, because the check for existence rejected P-files. I have an Excel file which contains more than 20 sheet. I am calling an external utility using dos which creates a file in the current directory. The thing is:I'm trying to develop a script to regularly copy files from a sourcefolder to a destinationfolder, but I wanted to make sure I copy only the most recent and modified data, in order to get a more efficient and quicker programme. Without the chance to modify the code, e.
This again is not a huge problem. For files you exists will return a 2 not a 1. This can often be avoided by identifying and closely inspecting before posting. The 'isfield' function examines only the top level of a nested structure. If you get a char out of it, that means your Matlab.
Can save both space and time. It is designed to check existence of other types of objects such as variables in Matlab as well as files. The solution here is to replace if exist 'filename','file' % your code with the line if java. If you're still having trouble reading it, try doing a lower level read with Java from within Matlab. My matlabpath is not too long about 200 entries and all folders on path are on my local drive no network.
That said, it may not be as bad as you think. You should also include the file extension in the check. Is this possible, or must I load it first like in the following example? More than 100 of Matlab's toolbox functions use this command to check the existence of files, e. Lukily this does not concern opening the file with write-access. However, if you save the. I the file is created correctly, but it cannot be seen by exist or fopen, which return 0 and -1 respectively.
You can use Java from within Matlab to do a simpler file existence test. I agree that the argument names and output values are confusing. Could you help me out, please?? Being a built in function, it's not a simple to see how it is coded. You mention xlsinfo is not available, but the actual function is called xlsfinfo! While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. The Matlab exist command is not a simple filesystem operation; it also looks at variables, functions, etc. But I need to dynamically create the file and then access it! The problem is for functions that do not append an extension and create a new file or follows an alternative processing path when the current file does not exist.
I assume, the smartness of fopen is more dangerous: It opens a file anywhere in the path, when the file name is relative. The documentation says little about checking if files exist. I am writing a module in Matlab where I need to check if a particular worksheet say for example 'SalaryData' is present in the Excel file. Btw, I was wondering if this check is purely done regarding the file name or the content in the file itself. Ls does not work with partial paths, which may be why it can see the file and the other functions can't. I intend to use actxserver to check the existence of the worksheet. The 'isfield' function returns true if a field is in a structure array.
However, I would like a function that determines if a field exists anywhere in a structure of structures. Here are a couple other workarounds, in case nsanders' two-arg exist or Jonas' change notification fixes don't work for you. If you want case insensitivity, use a loop and. The 'exist' function returns true if a structure with a particular name exists. If it's spending its time stepping through your path, that may help.
Therefore any function that adds an extension automatically will be okay. In these and user-defined functions, exist can fail in the cases I've described already. You could put the directory containing those header files up at the front of the path, so when exist goes looking through the path, it finds them quickly and doesn't have to search through the rest of the entries. So either the operating system is taking a long time, or there is some bloat in the exist function making it run slowly. . .