2024a vs 2024b detectImportOptions error

47 views (last 30 days)
Drew Jordison
Drew Jordison on 19 Mar 2025
Answered: Drew Jordison on 25 Mar 2025
I just updated my matlab to start using a new toolbox added to my license. I'm now getting an error that I was previously not getting. I can run both versions of matlab beside each other and am still successfully running it on 2024a but getting an error on 2024b. Because it's not got an error in 2024a I know that the file DOES exist and the path IS valid. Help?
"Error using detectImportOptions (line 428)
Unable to find file. Ensure file exists and path is valid.
Error in Scriptname (line 79)
opts = detectImportOptions(url,'FileType','text');"
  25 Comments
dpb
dpb on 21 Mar 2025
Edited: dpb on 22 Mar 2025
Yeah, you'll probably have to do something more like
...
[f,n,e]=fileparts(url); % parse the url parts
tempfile=char(fullfile(tempdir,strcat(n,'.txt'))); % create a temporary .txt file name
[status,msg]=copyfile(url,tempfile); % see if can copy it local file
...
to create a normal filesystem filename. This one would be the base name
>> [f,n,e]=fileparts(url)
f =
'https://catalogue.hakai.org/erddap/tabledap'
n =
'HakaiWaterPropertiesInstrumentProfileProvisional'
e =
'.csvp?&hakai_id="1907674_2021-09-23T17:01:55Z"'
>>
HakaiWaterPropertiesInstrumentProfileProvisional.txt in your temp dir
Or you could try and get more creative and try some variation such as
...
[f,n,e]=fileparts(url); % parse the url parts
tstr=extractBetween(url,'"','"'); % pull the time string out of the url
tempfile=char(fullfile(tempdir,strcat(n,tstr,'.txt'))); % create a temporary .txt file name
[status,msg]=copyfile(url,tempfile); % see if can copy it local file
...
The ? and " characters at least are invalid in Windows filenames, I guess the other alternative would be to replace them...
url=replace(url,{'&?"><'},{'_'});
first.
dpb
dpb on 22 Mar 2025
url='https://catalogue.hakai.org/erddap/tabledap/HakaiWaterPropertiesInstrumentProfileProvisional.csvp?&hakai_id="1907674_2021-09-23T17:01:55Z"'
url = 'https://catalogue.hakai.org/erddap/tabledap/HakaiWaterPropertiesInstrumentProfileProvisional.csvp?&hakai_id="1907674_2021-09-23T17:01:55Z"'
[f,n,e]=fileparts(url);
tstr=extractBetween(url,'"','"');
tempfile=char(fullfile(strcat(n,tstr,'.txt')))
tempfile = 'HakaiWaterPropertiesInstrumentProfileProvisional1907674_2021-09-23T17:01:55Z.txt'
[status,msg]=copyfile(url,tempfile)
status = logical
1
msg = 0x0 empty char array
dir *.txt
HakaiWaterPropertiesInstrumentProfileProvisional1907674_2021-09-23T17:01:55Z.txt
opt=detectImportOptions(tempfile) % will be 'Filetype','Text' based on file extension
opt =
DelimitedTextImportOptions with properties: Format Properties: Delimiter: {','} Whitespace: '\b\t ' LineEnding: {'\n' '\r' '\r\n'} CommentStyle: {} ConsecutiveDelimitersRule: 'split' LeadingDelimitersRule: 'keep' TrailingDelimitersRule: 'ignore' EmptyLineRule: 'skip' Encoding: 'UTF-8' Replacement Properties: MissingRule: 'fill' ImportErrorRule: 'fill' ExtraColumnsRule: 'addvars' Variable Import Properties: Set types by name using setvartype VariableNames: {'work_area', 'cruise', 'hakai_id' ... and 63 more} VariableTypes: {'char', 'char', 'char' ... and 63 more} SelectedVariableNames: {'work_area', 'cruise', 'hakai_id' ... and 63 more} VariableOptions: [1-by-66 matlab.io.VariableImportOptions] Access VariableOptions sub-properties using setvaropts/getvaropts VariableNamingRule: 'modify' Location Properties: DataLines: [2 Inf] VariableNamesLine: 1 RowNamesColumn: 0 VariableUnitsLine: 0 VariableDescriptionsLine: 0 To display a preview of the table, use preview
So, the copy does seem to work; the Q? then would be whether your system will then be able to open/process the local file that fails from the direct url request....

Sign in to comment.

Answers (2)

Kautuk Raj
Kautuk Raj on 25 Mar 2025
I was facing a similar error during one of my workflows wherein the "detectImportOptions" threw a "Unable to find file" error when filename was a URL in MATLAB R2024b.
As a workaround, I switched to using MATLAB R2024a.
Alternatively, you use a local copy of the CSV file to mitigate the issue in MATLAB R2024b.

Drew Jordison
Drew Jordison on 25 Mar 2025
I reported this and it was a replicable bug. I've reverted to 2024a for the time being.

Tags

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!