Matlab Coder Load function fails to locate files in subfolders

5 ビュー (過去 30 日間)
Christian
Christian 2013 年 4 月 25 日
I want to be able to load certain precomputed values from a .mat file during my automatically generated c-code. As far as I can see, I can use coder.load() for this (you may also point out any other options if you are aware of them). This works fine as long as the specified file is in the same folder as the project. For example S = coder.load('myfile.mat') works. However, as soon as I place the file in a subfolder and try S = coder.load('subfolder/myfile.mat') then I get an error "Failed to locate file 'subfolder/myfile.mat' specified in the load function".
I tried to use absolute paths, I tried adjusting the working folder in the settings, I tried to use add path, but with no success. Any help appreciated. I use Matlab 2013a on Mac Osx Mountain Lion.
EDIT: I used coder.load() not load()

回答 (3 件)

Yao Li
Yao Li 2013 年 4 月 25 日
You have to use the full path. For example,
S = load('c:\...\subfolder\myfile.mat');
Pls. use backslash '\' instead of forwardslash '/'.
  3 件のコメント
Yao Li
Yao Li 2013 年 4 月 25 日
Sorry, I left my air in the apartment. I may try on the laptop later.
Yao Li
Yao Li 2013 年 4 月 25 日
I have been programing on Mac Matlab for a long while. Generally, the codes on Mac OS are the same as on Win OS.

サインインしてコメントする。


Yao Li
Yao Li 2013 年 4 月 25 日
I've test the codes below on my macbook air, it ran well.
load('/Users/liyao21/Documents/MATLAB/aa/a.mat')
  2 件のコメント
Christian
Christian 2013 年 4 月 25 日
Have you tried using this line in a function and compile it with Matlab coder ( codegen test)?
function test() %#codegen
coder.load('/Users/liyao21/Documents/MATLAB/aa/a.mat')
Yao Li
Yao Li 2013 年 4 月 26 日
Sorry, I haven't used that. However, since coder.load() works well in the current path, why not try using cd() to specify the subfolder first and then coder.load()

サインインしてコメントする。


John Elliott
John Elliott 2013 年 4 月 26 日
You should add 'subfolder' to your path, then use coder.load('myfile.mat')

カテゴリ

Help Center および File ExchangeMATLAB Coder についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by