arrayDatastore Read cut dimension

2 views (last 30 days)
Odo Luo
Odo Luo on 18 Apr 2022
Commented: Walter Roberson on 18 Apr 2022
For a segmentation task I have a Hx Wx M items as matrix, I gonna convert into a logical array.
I would like to read these items into an arrayDatastore and tried following (simplified code):
for counter = 1:20
A= magic(10);
resultItem= cat(3,A,A,A);
result(counter,:,:,:)=resultItem;
end
result=logical(result<5& result>2);
ds=arrayDatastore(result,"ReadSize",1,"OutputType","same");
The read funktion sadly delivers a 1x4 dimensional array instead of 1x3. How can I clipp the first dimension - the counter - away ?
Or any other solution how to read everything into an arrayDatastore during a loop?

Answers (1)

Walter Roberson
Walter Roberson on 18 Apr 2022
result(:,:,:,counter)=resultItem;
  2 Comments
Odo Luo
Odo Luo on 18 Apr 2022
Sorry, I do not understand your answer
This still leaves me with a 1x4 array, just with the counter at the end
Walter Roberson
Walter Roberson on 18 Apr 2022
Sorry, it does not appear to be possible. The closest appears to be that you can return a scalar cell that is 3 dimensions. If you need a numeric return instead of a scalar cell then you are going to get a 4 dimensional object that you would then have to reshape() or permute() or squeeze()
for counter = 1:20
A = magic(10);
resultItem = cat(3,A,A,A);
result(:,:,:,counter) = resultItem;
end
result = logical(result<5& result>2);
ds = arrayDatastore(result,"ReadSize", 1, "OutputType", "cell", "IterationDimension", 4);
test1 = read(ds);
test2 = read(ds);
whos
Name Size Bytes Class Attributes A 10x10 800 double cmdout 1x33 66 char counter 1x1 8 double ds 1x1 8 matlab.io.datastore.ArrayDatastore result 10x10x3x20 6000 logical resultItem 10x10x3 2400 double test1 1x1 404 cell test2 1x1 404 cell
size(test1{1})
ans = 1×3
10 10 3

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!