주요 콘텐츠

이 번역 페이지는 최신 내용을 담고 있지 않습니다. 최신 내용을 영문으로 보려면 여기를 클릭하십시오.

ncwriteatt

R2026a

netCDF 파일에 특성 쓰기

    설명

    ncwriteatt(filename,location,attname,attvalue)는 filename으로 지정된 netCDF 파일에서 location으로 지정된 그룹 또는 변수에 attname으로 지정된 특성을 만들거나 수정합니다. 쓰여진 특성 값은 attvalue의 MATLAB® 데이터형과 가장 일치하는 netCDF 데이터형입니다. MATLAB이 가장 일치하는 유형을 결정하는 방법은 MATLAB에서 NetCDF로 데이터형 변환 항목을 참조하십시오.

    예제

    ncwriteatt(filename,location,attname,attvalue,"Datatype",dtype)은 attvalue를 dtype에 의해 지정된 데이터형으로 씁니다. 예를 들어, dtype을 "string"으로 지정하여 attvalue의 값을 string형으로 쓸 수 있습니다.

    예제

    예제

    모두 축소

    example.nc 파일의 쓰기 가능한 로컬 복사본을 만들고 전역 creation_date 특성의 값을 살펴봅니다.

    copyfile(which("example.nc"),"myfile.nc")
    fileattrib("myfile.nc","+w")
    creationDate = ncreadatt("myfile.nc","/","creation_date")
    creationDate = 
    '29-Mar-2010'
    

    modification_date 특성을 만들고 현재 날짜로 설정한 다음 그 값을 확인합니다.

    ncwriteatt("myfile.nc","/","modification_date",datestr(datetime("now")))
    modificationDate = ncreadatt("myfile.nc","/","modification_date")
    modificationDate = 
    '24-Jan-2026 19:49:38'
    

    example.nc 파일의 쓰기 가능한 로컬 복사본을 만들고 peaks 변수의 description 특성의 값을 살펴봅니다.

    copyfile(which("example.nc"),"myfile.nc")
    fileattrib("myfile.nc","+w")
    oldDescription = ncreadatt("myfile.nc","peaks","description")
    oldDescription = 
    'z = peaks(50);'
    

    특성을 업데이트하고 새 값을 확인합니다.

    ncwriteatt("myfile.nc","peaks","description","Output of PEAKS")
    newDescription = ncreadatt("myfile.nc","peaks","description")
    newDescription = 
    'Output of PEAKS'
    

    example.nc 파일의 쓰기 가능한 로컬 복사본을 만듭니다.

    copyfile(which("example.nc"),"myfile.nc")
    fileattrib("myfile.nc","+w")

    string형 배열 ["°F" "°C"]를 변수 /grid1/temp의 새 특성 Units의 값으로 씁니다. 이 배열은 netcdf4 형식의 파일에만 지원되는 비ASCII string형 데이터를 포함합니다.

    ncwriteatt("myfile.nc","/grid1/temp","Units",["°F" "°C"])

    새 특성의 값을 확인합니다.

    ncreadatt("myfile.nc","/grid1/temp","Units")
    ans = 1×2 string
        "°F"    "°C"
    
    

    이름이 Calendar인 변수가 있는 netCDF-4 형식 파일을 만듭니다. 그런 다음 데이터형을 "string"으로 지정하여 문자형 벡터 'July'를 Months라는 특성에 NC_STRING형으로 씁니다. 기본적으로 ncwriteatt는 스칼라 텍스트 데이터를 NC_CHAR형으로 씁니다.

    nccreate("myfile.nc","Calendar","Format","netcdf4")
    ncwriteatt("myfile.nc","Calendar","Months",'July',"Datatype","string")

    새 특성의 값과 데이터형을 확인합니다.

    ncreadatt("myfile.nc","Calendar","Months")
    ans = 
    "July"
    

    입력 인수

    모두 축소

    기존 netCDF 파일의 파일 이름으로, string형 스칼라 또는 문자형 벡터로 지정됩니다.

    netCDF 파일이 없는 경우 nccreate 함수를 사용하여 먼저 만듭니다.

    예: "myFile.nc"

    netCDF 파일에서 변수나 그룹의 위치로, string형 스칼라 또는 문자형 벡터로 지정됩니다. 전역 특성을 쓰려면 location을 "/"(슬래시)로 설정하십시오.

    예: "myVar"

    예: "/myGrp/mySubGrp/myNestedVar"

    예: "myGrp"

    예: "/myGrp/mySubGrp"

    쓰려는 특성 이름으로, string형 스칼라 또는 문자형 벡터로 지정됩니다.

    예: "myAttribute"

    특성 값으로, 숫자형 배열 또는 텍스트로 지정됩니다.

    참고

    attvalue가 둘 이상의 차원을 가지는 경우, ncwriteatt 함수는 특성 값을 쓰기 전에 열 우선 순서로 attvalue를 평탄화합니다. 예를 들어, attvalue를 [1 2 3; 4 5 6]로 지정하는 것과 attvalue를 [1 4 2 5 3 6]로 지정하는 것은 동일한 효과를 갖습니다.

    데이터형: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | char | string

    특성을 쓸 때 사용할 MATLAB 데이터형으로, 다음 표에 있는 값 중 하나로 지정됩니다. ncwriteatt는 netCDF 파일에서 특성을 만들거나 수정할 때 상응하는 netCDF 데이터형을 사용합니다.

    dtype의 값NetCDF 특성 유형
    "double"NC_DOUBLE
    "single"NC_FLOAT
    "int32"NC_INT
    "int16"NC_SHORT
    "int8"NC_BYTE
    "char"NC_CHAR
    "int64"(*)NC_INT64
    "uint64"(*)NC_UINT64
    "uint32"(*)NC_UINT
    "uint16"(*)NC_USHORT
    "uint8"(*)NC_UBYTE
    "string"(*)NC_STRING

    (*) 이 dtype 값은 netcdf4 형식의 파일에만 사용할 수 있습니다.

    예: "int16"

    데이터형: string | char

    세부 정보

    모두 축소

    버전 내역

    R2011a에 개발됨

    모두 확장