Why is microservice able to load 'txt' files from subdirectory but not ".mat" files?

조회 수: 4 (최근 30일)
consider this function loadFile.m:
function w = loadFile()
readlines("subdirectory/txtfile.txt")
load('subdirectory\someMatFile.mat')
w = 1;
end
Which I compiled using:
compiler.build.productionServerArchive
With options set to Include both files in subdirectory as 'Additional Files'. Then I compiled the function to a microservice using compiler.package.microserviceDockerImage.
The issue is - When I start the microservice as a docker container, the function is only able to read from the .txt file in the subdirectory, and not load the '.mat'. This Issue occurs only when loading mat file from subdirectory. if it is located in the same directory as function when compiling, loading is available when running as container.
I modified the DockerFile and rebuilt the image to make the script run as root, so I am confident this isn't a permissions issue.
The error message recieved in the http response:
"error":{"id":"MATLAB:load:couldNotReadFile","message":"Unable to find file or directory 'subdirectory\\someMatFile.mat'}

채택된 답변

Fangjun Jiang
Fangjun Jiang 2024년 3월 27일
편집: Fangjun Jiang 2024년 3월 27일
Notice the two backslashes "\\" in the error message about the file?
"error":{"id":"MATLAB:load:couldNotReadFile","message":"Unable to find file or directory 'subdirectory\\someMatFile.mat'}
Does it make a difference between slash "/" and back slash "\"? Try to use
fullfile('subdirectory','someMatFile.mat')
ans = 'subdirectory/someMatFile.mat'
filesep
ans = '/'
  댓글 수: 1
Aran Ofer
Aran Ofer 2024년 3월 28일 10:33
Thanks, Error turned out to be a combination of path specification and partial inclusion of Additional Files at compilation.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 COM Component Integration에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by