Matrix-concatenation-generated c/c++ code is incompatible with MATLAB
Show older comments
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
Answers (2)
Walter Roberson
on 8 Mar 2018
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
on 8 Mar 2018
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!