Matrix-concatenation-generated c/c++ code is incompatible with MATLAB
Mostrar comentarios más antiguos
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
Respuestas (2)
Walter Roberson
el 8 de Mzo. de 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
el 8 de Mzo. de 2018
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!