suppose i have A=ones(10,1)*10
then what does this do eye(10)(A,:) ??
i know eye gives a 10,10 identity matrix but i am not really sure what the above code is doing.
and what is the equivalent code in Matlab?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A=ones(10,1)*10just makes a column matrix (10 rows, 1 column) of 10s.eye(10)makes a 10×10 identity matrix.The
(A,:)indexes into the identity matrix you just made. TheAhere acts as a numeric index into theeye(10)matrix. SupposeAwas just 10. Then themyMatrix(A,:)would select the 10th row ofmyMatrix. SinceAis 10 rows of 10,myMatrix(A,:)selects the 10th row ofmyMatrix, 10 times. So you get back out the 10th row ofeye(10)10 times.It may be less confusing if you do
A=ones(5,1)*10and have a look ateye(10)(A,:); notice that you now only get the 10th row ofA5 times.You can’t do this as such in Matlab because it doesn’t let you do the one-hit
eye(10)(A,:). You have to do it in two steps:More on various types of matrix indexing in Matlab.