Skip to content

Commit 5286555

Browse files
committed
ncsize: handle scalar, vector more accurately
1 parent d23753d commit 5286555

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

+stdlib/+hdf5nc/ncsize.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616

1717
assert(isfile(file), "%s not found", file)
1818

19-
fsize = ncinfo(file, variable).Size;
19+
dsi = ncinfo(file, variable);
20+
if isempty(dsi.Dimensions)
21+
fsize = [];
22+
else
23+
fsize = dsi.Size;
24+
end
2025

2126
end

+stdlib/TestNetCDF.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ function test_size(tc)
8383
basic = tc.TestData.basic;
8484

8585
s = ncsize(basic, 'A0');
86-
tc.verifyThat(s, IsScalar)
87-
tc.verifyEqual(s, 1)
86+
tc.verifyEmpty(s)
8887

8988
s = ncsize(basic, 'A1');
9089
tc.verifyThat(s, IsScalar)

Readme.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,18 @@ If dataset exists, the existing dataset shape must match the variable.
9797
ncsave(filename, variable_name, variable)
9898
```
9999

100+
---
101+
100102
Get the dataset size (shape)
101103

102104
```matlab
103105
ncsize(filename, variable_name)
104106
```
105107

108+
A scalar disk variable will return empty `[]`.
109+
110+
---
111+
106112
Get the names of all datasets in a file
107113

108114
```matlab

0 commit comments

Comments
 (0)