Non-constant expression or empty matrix. This expression must be constant because its value determines the size or class of some expression.

7 ビュー (過去 30 日間)
Hello,
I'm trying to use the MATLAB coder and getting the above error when loading a mat file.
My code:
data = struct('Value',zeros(500,1)); %% No change with or without this line
data = load(Folder+"\Value.mat"); %% Error on this line
All_data(:,1) = data.Value;
Thank you
  2 件のコメント
Matt J
Matt J 2023 年 3 月 26 日
編集済み: Matt J 2023 年 3 月 26 日
What is the result if yolu just evaluate the argument to load()?
Folder+"\Value.mat"
Tal Levy
Tal Levy 2023 年 3 月 27 日
load(Folder+"\Value.mat")
Returns a vector (named "Value").
But the coder can't handle load without placing it in a variable

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

回答 (2 件)

Abhijeet
Abhijeet 2023 年 4 月 5 日
Hi,
The error message you received suggests that the expression you are using to load data is not constant or is an empty matrix, which makes it impossible to determine the size or class of the expression.
Here are some steps you can take to resolve this error:
  1. Check that the path to the folder containing the file you want to load is correct. Make sure that the folder path is enclosed in quotes if it contains spaces.
  2. Check that the file you are trying to load exists in the specified folder.
  3. Make sure that the file you are trying to load is in the correct format for the function you are using to load it. For this case, if you are using the load() function, the file must be a .mat file.
  4. Check that the variable "Folder" has been defined and is pointing to the correct folder.
  5. Make sure that the expression you are using to load data is constant and not an empty matrix.
Hope these may resolve your errors.
  2 件のコメント
cui,xingxing
cui,xingxing 2023 年 4 月 18 日
Hi, I'm getting a similar error message but I've tried many things and still can't solve it, any better suggestions? Thank you. my problem is following link.
Ryan Livingston
Ryan Livingston 2023 年 4 月 18 日
I added a comment there. Your example triggers this same message for a different reason. Walter's answer summarizes the limitation and I added a debugging/sanity checking step you can use when generating struct field names.

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


Ryan Livingston
Ryan Livingston 2023 年 4 月 5 日
編集済み: Ryan Livingston 2023 年 4 月 5 日
For code generation, the file name input to load must be a constant:
So here Coder is trying to tell you that Folder+"\Value.mat"is not constant and that it can't deal with that. This error is confusing, so I've made an internal note for our team to improve the message in the future.

カテゴリ

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

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by