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

35 Ansichten (letzte 30 Tage)
Odin Iversen
Odin Iversen am 18 Okt. 2020
Kommentiert: Rik am 18 Okt. 2020
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

Akzeptierte Antwort

Bruno Luong
Bruno Luong am 18 Okt. 2020
full(M(3,3))

Weitere Antworten (2)

Rik
Rik am 18 Okt. 2020
You can convert the result to a full matrix. Indexing only extracts part of the array, but doesn't influence the sparse property.
  2 Kommentare
Odin Iversen
Odin Iversen am 18 Okt. 2020
so like this:
full(M(3,3))
this only converts that one element to full and not the whole M-matrix in the process?
Rik
Rik am 18 Okt. 2020
Exactly, which is probably why you accepted Bruno's answer.

Melden Sie sich an, um zu kommentieren.


Ameer Hamza
Ameer Hamza am 18 Okt. 2020
Or maybe this
M(3,3)+0

Kategorien

Mehr zu Sparse Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by