特定の値(欠損値)を削除する方法

19 views (last 30 days)
健気 大川
健気 大川 on 17 Sep 2021
Commented: 健気 大川 on 17 Sep 2021
イメージ画像を下に載せます。
例えばmatlab上(画像はexcelですが)で左のような5行7列の行列があったとします。これを右のように0の部分を削除したものを作りたいです。
どなたかお時間がある方助言をお願いしたいです。(ただし、今回は例として5行7列ですがほかの行列パターンでも用いたいです。また、0は欠損値のような扱いで途中で現れることはありません。)

Accepted Answer

Hernia Baby
Hernia Baby on 17 Sep 2021
ゼロ値をNaN値にすればいけます
file = 'Sample.xlsx';
A = readmatrix(file,"OutputType","double");
ここがミソです
A(A==0) = NaN
A = 5×7
1 2 4 8 11 13 18 NaN 3 5 9 12 14 19 NaN NaN 6 10 NaN 15 20 NaN NaN 7 NaN NaN 16 NaN NaN NaN NaN NaN NaN 17 NaN
書き出します
writematrix(A,file,'Range','K2');
  1 Comment
健気 大川
健気 大川 on 17 Sep 2021
いつもお忙しい中ありがとうございます。こんな初歩的な質問ですみませんでした。

Sign in to comment.

More Answers (0)

Categories

Find more on イメージ in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!