【问题标题】:Saving string column into NetCdf file将字符串列保存到 NetCdf 文件中
【发布时间】:2022-11-08 02:59:11
【问题描述】:

我想使用 MATLAB 将字符串数据保存到 NetCDF 文件中的单个列中,没有为字符串提供选项。有人能告诉我如何将字符串数据保存到 NetCDF 文件中吗?

S_rebuilt=["101670";"101670";"101670";"101670"]

nccreate('file_name.nc','S_rebuilt',...
     'Dimensions', {'x',size(S_rebuilt,1),'y',size(S_rebuilt,2)},...
     'FillValue','disable');

ncwrite('file_name.nc','S_rebuilt',S_rebuilt);

【问题讨论】:

  • 你有数字数据。为什么要将其保存为字符串?
  • 不,我也有字符串数据。这些只是包含数字的几行。但是我有其他行和列相等的字符串(字符)数据,我想保存在 NetCDF 文件中。

标签: string matlab char netcdf


【解决方案1】:

使用格式netcdf4,可以在MatLab 中使用数据类型string。因此,要将变量 S_rebuilt 保存为字符串,我建议使用以下代码:

filename = 'file_name.nc'
S_rebuilt = ["101670";"101670";"101670";"101670"]

nccreate(filename,'S_rebuilt',...
     'Dimensions', {'nvars',length(S_rebuilt)},...
     'Datatype','string','format','netcdf4');
% ----------------------------------------------
ncwrite(filename,'S_rebuilt',S_rebuilt);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-03
    • 2014-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多