How do I write a sparse matrix in MATLAB

2 件のコメント

Daniel Pollard
Daniel Pollard 2020 年 12 月 15 日
Shlesha Van
Shlesha Van 2020 年 12 月 15 日
That gives solutions on how to convert a full matrix into sparse. My case is opposite. I want to convert a sparse into full

サインインしてコメントする。

回答 (2 件)

Daniel Pollard
Daniel Pollard 2020 年 12 月 15 日
編集済み: Daniel Pollard 2020 年 12 月 15 日

2 投票

https://uk.mathworks.com/help/matlab/ref/full.html

4 件のコメント

Shlesha Van
Shlesha Van 2020 年 12 月 15 日
Thanks Daniel, but how do I type this matrix in Matlab?
I tried A = [ 2 -1 0 ... 0;]; but everything after ... turns green.
Daniel Pollard
Daniel Pollard 2020 年 12 月 15 日
An ellipsis ... has a very specific meaning in Matlab. If you type it in, it interprets that to mean "the next line is a continuation of this line". It does not mean "fill in the numbers here". A sparse matrix is a specific thing, and if you try to enter exactly the A in your question into Matlab, you'll have a bad time. I recommend reading the documentation to get a clearer idea of what's going on.
Shlesha Van
Shlesha Van 2020 年 12 月 15 日
Jan
Jan 2020 年 12 月 16 日
The first two inputs of sparse() are the size of the matrix. As the error message tells you, [2,-1,0] cannot be a valid size. See the documentation of sparse :
doc sparse

サインインしてコメントする。

Jan
Jan 2020 年 12 月 15 日

2 投票

You want to convert a sparse matrix into a full one? Then use the command: full().

カテゴリ

ヘルプ センター および File ExchangeSparse Matrices についてさらに検索

質問済み:

2020 年 12 月 15 日

コメント済み:

Jan
2020 年 12 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by