MATLAB Answers

Crossover applications in matlab

조회 수: 8(최근 30일)
I want to apply crossover betweem x1 and x2
x1=[ -1.0000 - 1.0000i 2.0000 - 2.0000i 3.0000 - 3.0000i];
x2=[ -4.0000 - 4.0000i 5.0000 - 5.0000i 6.0000 - 6.0000i];
CrossoverIndex=1;
>> c2 = [x2(1:CrossoverIndex) x1(CrossoverIndex+1:end)];
But i found this error:
Error using horzcat
Dimensions of matrices being concatenated are not consistent.
Can any one help me how can i solve the error.

  댓글 수: 0

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 7 Jan 2019
you show x1 and x2 as row vectors but your code is p1 and p2. If p1 and p2 are column vectors you would have problems with your [] operation if the crossover was not exactly half way . II suspect you should use ; between the parts.

  댓글 수: 4

표시 이전 댓글 수: 1
Walter Roberson
Walter Roberson 7 Jan 2019
command
dbstop if error
then run the code. when it stops show size(x1) and size(x2)
Johan Johan
Johan Johan 7 Jan 2019
Thank you very much, the problem is solved if using the transpose operation :
c2 = [x2(1:CrossoverIndex)' x1(CrossoverIndex+1:end)'];
Walter Roberson,do you know why solved by add the transpose operation ?
Walter Roberson
Walter Roberson 7 Jan 2019
If the code you posted were the only code that were in place, then it would have been correct. I suspect that you are passing those values into a function that is transposing them.

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by