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

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

 Respuesta aceptada

Hernia Baby
Hernia Baby el 17 de Sept. de 2021

1 voto

ゼロ値を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 comentario

健気 大川
健気 大川 el 17 de Sept. de 2021
いつもお忙しい中ありがとうございます。こんな初歩的な質問ですみませんでした。

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre 数値型 en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 17 de Sept. de 2021

Comentada:

el 17 de Sept. de 2021

Community Treasure Hunt

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

Start Hunting!