Creating a better version of the diag function

MATLAB-specific help discussions.

Creating a better version of the diag function

Postby linda » Fri Dec 25, 2009 10:10 am

Hi,
I need to extract the main diagonal of a matrix with lower complexity than the "diag" function has. I tried the following simple loop:

for i=1:length(a)
my_diag(i)=a(length(a)*(i-1)+i)
end

Unsurprisingly it works, but it's much slower than "diag".
Any ideas?

Thanks
linda
 
Posts: 1
Joined: Fri Dec 25, 2009 10:03 am

Return to MATLAB Help

Who is online

Users browsing this forum: No registered users and 2 guests