Converting .m to C code using Matlab Coder
4 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I am trying to convert MATLAB script to C code using Matlab coder.
%Source file
10 load data.mat; % this mat file has data of the structure struct_1
11 for k=1:5
12 struct_2(k).struct_1=struct_1;
13 struct_2(k).Out=interp2(struct_2(k).struct_1.in1,struct_2(k).struct_1.in2,struct_2(k).struct_1.in3,struct_2(k).P,struct_2(k).Q,'makima');
14
15 end
I received data.mat from other source and asked me to convert it to C. When I try to convert it to C, I got error variable struct_1,struct_2 must be initialised before subscripting. So i went to source code, run it and in workspace i found fields of both struct's and given the same dimensions. Now I initialised with fields of struct_1
%codegen
struct_1 =struct('in1',zeros(5,10),...
'in2', zeros(5,10),...
'in3', zeros(5,10),...
...%there are some more fields
...
);
struct_2 = struct( 'struct_1',struct_1,...
'Out', zeros(100,3),...
'P', Zeros(100,3),...
'Q'zeros(100,3),...
... ...%there are some more fields
);
Now i try to generate C code, this time error in line 13 size Mismatch, to resolve I used coder.varsize, and then it is showing Interpolation method must be one of the following: 'cubic', 'linear', 'nearest', or 'spline' and function call failed. I used repmat for struct_2 then this error is gone. Finally I am in code generation step now it is showing
Error using unmeshgrid (line 28)
Grid values must be strictly increasing.
Error in interp2 (line 70)
unmeshgrid(X,2),unmeshgrid(Y,1));
Error in line 13
I searched in matlab documentation, mathwork answers, stackoverflow and try to reslove errors but it is getting complicated for each step.
I think initialising data i.e(zeros(5,10) from output is wrong), it would be nice if you tell me how to proceed. I am trying this from past 5 days, still im not yet suceed.
if there is something wrong in my question or if anything is unclear feel free to ask.
Thank You.
0 件のコメント
回答 (1 件)
Steven Lord
2021 年 4 月 2 日
Certain functions have additional limitations in a code generation context using MATLAB Coder. See the Extended Capabilities section at the end of the function's documentation page to see which extended capabilities it supports and whether or not there are any limitations.
For the interp2 function there is a C/C++ Code Generation item in the Extended Capabilities section that lists a few limitations. The documentation page for the load function also has a C/C++ Code Generation item with some usage notes and limitations.
1 件のコメント
Naga Manoj Kumar Lakkoju
2021 年 4 月 2 日
編集済み: Naga Manoj Kumar Lakkoju
2021 年 4 月 2 日
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!