How to write only non-NaN columns into Excel

3 ビュー (過去 30 日間)
Leon
Leon 2019 年 10 月 15 日
編集済み: Leon 2019 年 10 月 16 日
Below is my code to write these column data into an Excel spreadsheet using the writetable command:
T1 = table(Cruise, EXPOCODE, Station_no, Lon, Lat, Year, Month, Day, Time, Pressure, Depth, ...
Temperature, Temperature_flag_W, Salinity, Salinity_flag_W, CTDOXY, CTDOXY_flag_W, OXYGEN, OXYGEN_flag_W, ...
DIC, DIC_flag_W, TA, TA_flag_W, pH_insitu, pH_flag_W, pCO2_insitu, pCO2_flag_W, CO3_insitu, CO3_flag_W, ...
Silicate, Silicate_flag_W, Phosphate, Phosphate_flag_W, Nitrate, Nitrate_flag_W, ...
NitrateNitrite, NitrateNitrite_flag_W, Nitrite, Nitrite_flag_W, Ammonium, Ammonium_flag_W);
File_W = ['outputs/', app.File.Value, '.xlsx'];
writetable(T1, File_W)
The thing is that sometimes an entire column could be made up of NaNs or missing value indicators, -999. How do I write a program, so that it will only use the variables that have at least one real value into the final Excel file? If a column is composed of either NaN or -999 values, the entire column, as well as its corresponding flag column (made up of numerical number 5), should not appear in the generated Excel file.
Many thanks!

回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2019 年 10 月 15 日
編集済み: Andrei Bobrov 2019 年 10 月 15 日
T_in_Excel = T1(:,any(~isnan(T1{:,:})));
writetable(T_in_Excel, File_W)
  3 件のコメント
Andrei Bobrov
Andrei Bobrov 2019 年 10 月 15 日
I'm fix.
Leon
Leon 2019 年 10 月 16 日
As a reminder, would you please help me with the flag column as well?
Many thanks!

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

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by