ncwriteatt
netCDF 파일에 특성 쓰기
구문
설명
ncwriteatt(
는 filename
,location
,attname
,attvalue
)filename
으로 지정된 netCDF 파일에서 location
으로 지정된 그룹 또는 변수에 attname
으로 지정된 특성을 만들거나 수정합니다. 쓰여진 특성 값은 attvalue
의 MATLAB® 데이터형과 가장 일치하는 netCDF 데이터형입니다. MATLAB이 가장 일치하는 유형을 결정하는 방법은 MATLAB에서 NetCDF로 데이터형 변환 항목을 참조하십시오.
예제
전역 특성 만들기
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 = '25-Jan-2024 21:36:51'
변수 특성 수정하기
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'
비ASCII 데이터를 특성으로 쓰기
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 = 1x2 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"
입력 인수
filename
— 파일 이름
string형 스칼라 | 문자형 벡터
기존 netCDF 파일의 파일 이름으로, string형 스칼라 또는 문자형 벡터로 지정됩니다.
netCDF 파일이 없는 경우 nccreate
함수를 사용하여 먼저 만듭니다.
예: "myFile.nc"
location
— 변수 또는 그룹의 위치
string형 스칼라 | 문자형 벡터
netCDF 파일에서 변수나 그룹의 위치로, string형 스칼라 또는 문자형 벡터로 지정됩니다. 전역 특성을 쓰려면 location
을 "/"
(슬래시)로 설정하십시오.
예: "myVar"
예: "/myGrp/mySubGrp/myNestedVar"
예: "myGrp"
예: "/myGrp/mySubGrp"
attname
— 특성 이름
string형 스칼라 | 문자형 벡터
쓰려는 특성 이름으로, string형 스칼라 또는 문자형 벡터로 지정됩니다.
예: "myAttribute"
attvalue
— 특성 값
숫자형 배열 | 텍스트
특성 값으로, 숫자형 배열 또는 텍스트로 지정됩니다.
참고
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
dtype
— MATLAB 데이터형
"double"
| "single"
| "int32"
| ...
특성을 쓸 때 사용할 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
세부 정보
MATLAB에서 NetCDF로 데이터형 변환
netCDF 관련 MATLAB 함수는 아래 표에 따라 MATLAB 데이터형과 가장 일치하는 netCDF 데이터형을 자동으로 선택합니다.
MATLAB 데이터형 | NetCDF 데이터형 |
---|---|
double | NC_DOUBLE |
single | NC_FLOAT |
int32 | NC_INT |
int16 | NC_SHORT |
int8 | NC_BYTE |
char | NC_CHAR |
string 스칼라 | NC_CHAR |
int64 (*) | NC_INT64 |
uint64 (*) | NC_UINT64 |
uint32 (*) | NC_UINT |
uint16 (*) | NC_USHORT |
uint8 (*) | NC_UBYTE |
string 형 벡터(*) | NC_STRING |
(*) 이 MATLAB 데이터형은 netcdf4
형식의 파일에만 사용할 수 있습니다.
버전 내역
R2011a에 개발됨R2021b: NC_STRING
특성을 쓸 수 있음
netCDF-4 파일에 NC_STRING
특성을 쓸 수 있습니다.
MATLAB 명령
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 MATLAB 명령을 지원하지 않습니다.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)