フィルターのクリア

How do I declare a variable non-automatically on Matlab?

3 ビュー (過去 30 日間)
Ricardo Sampaio
Ricardo Sampaio 2015 年 9 月 15 日
回答済み: dpb 2015 年 9 月 15 日
I'm trying to use Matlab coder to generate a C file from a Matlab code. However, when I build the project it doesn't recognize one of my local variables properly - it mistakes its class - giving the following error: "Undefined function or variable 'B'. The first assignment to a local variable determines its class." It was supposed to be a struct array, but it's recognized as an unknown class of size 1x1. I've tried to assign it as an array from the beggining as the first lines of my code are:
B(n,n).obs=0; %n is the array size
B(n,n).custo=0;
B(n,n).visitado=0;
Although it still does not work!

採用された回答

Titus Edelhofer
Titus Edelhofer 2015 年 9 月 15 日
Hi Ricardo,
you can use struct and repmat to initialize your structure:
B = repmat( struct( ...
'obs', 0, ...
'custo', 0, ...
'visitado', 0), n, n);
Titus

その他の回答 (1 件)

dpb
dpb 2015 年 9 月 15 日
Don't have the coder to test, but how about
>> B=struct('obs',0,'cust',0,'visit',0)
B =
obs: 0
cust: 0
visit: 0
>> whos B
Name Size Bytes Class Attributes
B 1x1 396 struct
>>
Setting B(n,n) on LHS of above will generate a structure array of that size. Now whether the coder is capable-enough to implement structures you'll have to check the documentation to tell.

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by