How can i extract the value of an element of a sparse double?

40 次查看(过去 30 天)
if i have a sparse duble:
M = zeros(3);
M = sparse(M);
M(3,3) = 2;
and i want to get only the value of M(3,3) = 2, how do i do that?
if i type:
M(3,3)
i get:
ans =
(1,1) 2
but i want to somheow get:
ans =
2
converting to full matrix is not an option since the actual matrix is 50000 x 50000. thank you

采纳的回答

Bruno Luong
Bruno Luong 2020-10-18

更多回答(2 个)

Rik
Rik 2020-10-18
You can convert the result to a full matrix. Indexing only extracts part of the array, but doesn't influence the sparse property.
  2 个评论
Odin Iversen
Odin Iversen 2020-10-18
so like this:
full(M(3,3))
this only converts that one element to full and not the whole M-matrix in the process?

请先登录,再进行评论。


Ameer Hamza
Ameer Hamza 2020-10-18
Or maybe this
M(3,3)+0

类别

Help CenterFile Exchange 中查找有关 Sparse Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by