Matrix-concatenation-generated c/c++ code is incompatible with MATLAB
Ältere Kommentare anzeigen
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
Antworten (2)
Walter Roberson
am 8 Mär. 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
am 8 Mär. 2018
Kategorien
Mehr zu Logical finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!