フィルターのクリア

Sparse metrix higher value as input value

5 ビュー (過去 30 日間)
Frederic Stichler
Frederic Stichler 2023 年 11 月 13 日
回答済み: Harald 2023 年 11 月 13 日
I want to create a sparse matrix and then sort it. But after initialisation, the highest value in the sparse matrix is higher than the highest input value.
load('inputs.mat');
vertexFaceConnectivity=sparse(F(:),ind,ind,numVertices,numFaces);
vertexFaceConnectivity=sort(vertexFaceConnectivity,2,'descend');
max(vertexFaceConnectivity(:)) % 3658
ans =
(1,1) 3658

回答 (1 件)

Harald
Harald 2023 年 11 月 13 日
Hi Frederic,
you may not be using sparse the way you intend. In this syntax, the third input is the values of the sparse matrix. Perhaps, you wanted something more like
vertexFaceConnectivity=sparse(ind,ind,F(:),numVertices,numFaces);
Since ind repeats values, that however would mean that you are setting the same values repeatedly - is that intended?. sparse then sums those values, as you can see in this mini-example:
ind = [1 2 3 1 2 3];
F = 1:6;
sparse(ind, ind, F)
ans =
(1,1) 5 (2,2) 7 (3,3) 9
If I had to guess, I would think that you intended to create a tri-diagonal matrix? I would use spdiags for that.
Best wishes,
Harald

カテゴリ

Help Center および File ExchangeSparse Matrices についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by