indexing for a single for loop of an upper triangular matrix

3 次查看(过去 30 天)
Hello everyone,
I had a question and was wondering if it is even possible. I want to create a square matrix using some comparison function. The matrix is symmetric by nature of this function. I want to write the comparisons using a single for loop but only want the for loop to use the indices of an upper triangular matrix. How would I do this in matlab? Thank you in advance.

回答(1 个)

Matt J
Matt J 2013-4-26
编辑:Matt J 2013-4-26
If U is the upper-triangular matrix,
Iset=nonzeros(triu( reshape(1:numel(U), size(U)) ));
for i=Iset
....
end

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by