1

Im rewriting matlab code to C#. I have no idea about programming in matlab and I can't understand this part:

d9=[d9 d8];
d10=d9(:,2:10);
d5=[d6 d10 d7];

Variables d6, d7, d8 and d9 are 2-dimensional arrays.

Full Matlab code is here: link to codeforge.com

2 Answers 2

2

"I have no idea about programming in matlab and I can't understand this part"

a) d9=[d9 d8];

will concatenate the matrix d9 and d8 and store result in d9. Other way is that it just append matrix d8 to d9

Example :

>> a=[1 2;3 4]

a =

     1     2
     3     4

>> b=[5 6;7 8]

b =

     5     6
     7     8

>> a=[a b]

a =

     1     2     5     6
     3     4     7     8

b) d10=d9(:,2:10);

: is colon operator extensively used for vector manipulation, sub-scripting and creating for loops iterator

Here,

second subscript 2:10 means the columns number 2 3 4...10 in d9

first subscript : all rows in d10

So d10 is assigned by all elements in column 2 to 10 from all rows of d9.

Example :

>> c=a(:,2:4)

c =

     2     5     6
     4     7     8

c) d5=[d6 d10 d7];

Again similar to first one, concatenates matrices d6 d10 and d7 and assign the result to d5.

Sign up to request clarification or add additional context in comments.

1 Comment

That explains everything. Thanks.
0

not yet able to comment directly under an answer but I think there is a typo in P0W's answer.

It should state:

" first subscript : all rows in d9 " (emphasis added) instead of " first subscript : all rows in d10 "

The rest of the answer is correct but just in case it confuses somebody unfamiliar with Matlab...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.