Matrix-concatenation-generated c/c++ code is incompatible with MATLAB
古いコメントを表示
Hello,
I did the following:
A = [0 1;1 0];
B = [1;2];
C = [A B];
then I generated a c++ code that calculates C. Matlab yields:
C = [0 1 1;1 0 2];
while c++ yields different result namely:
C = [0 1;1 0;1 2];
Does anybody know the reason for this incompatibility? Any suggestion how to overcome this problem?
Best regards,
Mohamed
回答 (2 件)
Walter Roberson
2018 年 3 月 8 日
while c++ yields different result namely:
C = [0 1;1 0;1 2];
Does it? Remember in C and C++ matrices are indexed across first rather than down like in MATLAB, so in MATLAB a 2 x 3 array C has C(1,1) directly before C(2,1) in memory. To replicate the in-memory order in C++ would involve double C[3][2]
Ichaoui
2018 年 3 月 8 日
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!