mldivide does not support sparse inputs for code generation

Hey
Is there any function which can be replaced with 'mldivide'.
Actually I am trying to make generate C code for 'regionfill' command. But I think because of 'mldivide' inside the regionfill, it is not generating C code.
How can Isolve this problem?

回答 (1 件)

Rik
Rik 2018 年 7 月 10 日

1 投票

You can try making a copy of this function, and editing it, so you avoid the sparse function, as that is causing the problem here:
i=[1 2 1];j=[1 1 2];s=[3 2 1];
D_original_code=sparse(i,j,s);
D=zeros(max(i),max(j));
D(sub2ind(size(D),i,j))=s;
isequal(D,full(D_original_code))
The tricky thing is that the sparse function is there for a reason: it makes things more efficient. You only need to hope either method (using full or filling a zeros) will not decrease the efficiency so much that generating C code and running the compiled code is not useful anymore.
Last note: don't edit the actual Matlab function, but create a copy. That might mean you are no longer allowed to share your compiled function, as it contains code by the Mathworks.

3 件のコメント

JAI PRAKASH
JAI PRAKASH 2018 年 7 月 10 日
I think it is not gonna be easy for me :(
Rik
Rik 2018 年 7 月 10 日
I think we discovered why it uses a sparse array...
Now your job becomes much more difficult: re-implementing mldivide, looking through its code (or using third party solvers). What is that pcg line? You could try if that one supports sparse arrays.
JAI PRAKASH
JAI PRAKASH 2018 年 7 月 10 日
pcg is an alternative to mldivide.
This pcg solves faster than mldivide but unfortunately does not supported by Matlab Coder.
So I think thats why regionfill is also not supported by matlab coder.

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

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

製品

リリース

R2018a

質問済み:

2018 年 7 月 10 日

コメント済み:

2018 年 7 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by