[MATLAB Compiler] I want to run a Python package created on Linux on Windows. I get an error when specifying the path to the folder.

I want to read a file and process it in Matlab.
On Linux, the file is specified as follows.
filename = ['/home/test/file.csv'];
When we convert the file to a PythonPackage using Matlab Compiler on Ubuntu, and run Python on Ubuntu, it succeeds.
Modify the path so that it can be run on Windows as well.
filename = ['C:\test\file.csv'];
When using the Matlab Compiler after the modification, the following error is encountered.
The function or variable 'x' is not recognized.
How do I specify the path to a folder to make a PythonPackage on Linux and run it on Windows?

 Accepted Answer

Did you try:
filename = ['C:/test/file.csv'];
Or
filename = ['C:\\test\\file.csv'];
'\t' has special meaning, and it might confuse matlab.

3 Comments

Thanks for the reply.
I tried the case you commented on, but it failed.
It's on Ubuntu.
I think the export function is executed when the PythonPackage is created in Matlab Compiler.
The following is the Windows directory, so the "file.csv" is not found and an error occurs.
filename = ['C:/test/file.csv'];
filename = ['C:\\ test\file.csv'];
I think you need either of the following
  • Ignore this error and convert to PythonPackage
  • Make it look like "file.csv" is in the above directory on Ubuntu
  1. Most Winodws apps accept Linux style file path. So maybe something else is wrong, not the file path
  2. If you want to use Windows style, you need to escape both '\'. It has to be filename = ['C:\\test\\file.csv']. You have an extra space before test, and you didn't escape the '\' before file.
  3. Why do you want to hard code the file path in the matlab code? Does it make more sense to use the python code to pass the file path to the matlab code?
Thanks for the reply.
  1. It's not a problem on the Windows side, but on the Linux side when running Matlab Compiler.
  2. Sorry, the extra space was a copy and paste mistake.The actual program handled it without the extra space.
  3. I was thinking of hardcoding it because I wanted to read the file in matlab and process it, but the Matlab Compiler would fail if I hardcoded it, so I changed it to process it with relative paths.With the following, Matlab Compiler succeeded and I can now run it on Windows.
- filename = ['/home/test/file.csv'];
+ filename = pwd
+ filename = strcat(filename + "/file.csv")
Thanks for your support!

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2021a

Community Treasure Hunt

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

Start Hunting!