Matrix-con​catenation​-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

Respuestas (2)

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]
Thanks for your answer,
but I think my example was a little bit confusing and does not show the problem I'm facing. Because A is symmetric one would think it is just a matter of Transposition. Here another is example:
A = [1 2;3 4];
B = [5;6];
C = [A B];
with the in c++ generated function I get (as an array not as a matrix)
C = [1 2;3 4;5 6];
or just as an array
1 2 3 4 5 6
rather than
C = [1 2 5;3 4 6];
thanks,
Mohamed

Categorías

Preguntada:

el 8 de Mzo. de 2018

Respondida:

el 8 de Mzo. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by