필터 지우기
필터 지우기

ArrayDatastore 2x1 combine to 1 column

조회 수: 2 (최근 30일)
Odo Luo
Odo Luo 2022년 4월 12일
댓글: Odo Luo 2022년 4월 13일
Hello, I would like to combine 2 arrayDatastores vertically.
I tried it with combine and permute, but it always gives a 1x2 instead of a 2x1 back:
A = cat(3,magic(10),magic(10),magic(10));
B = cat(3,magic(10),magic(10),magic(10));
a1= arrayDatastore(A);
a2= arrayDatastore(B);
a3= combine(a1,a2);
a4=tall(a3);
a5=cellfun(@(im) permute(im,[2,1]),a4, 'UniformOutput', false);
Need to combine it with other datastores later.

채택된 답변

Sreehari Hegden
Sreehari Hegden 2022년 4월 12일
If you are looking to combine 2 ArrayDatastores vertically to essentially merge their data, one option would be to do a vertcat of readall outputs from both the ArrayDatastores a1 and a2.
A = cat(3,magic(10),magic(10),magic(10));
B = cat(3,magic(10),magic(10),magic(10));
a1= arrayDatastore(A);
a2= arrayDatastore(B);
data = vertcat(readall(a1), readall(a2))
You can also consider writing these data to files and then construct a single TabularTextDatastore or SpreadsheetDatastore from the files.
Another sustainable option would be to write a custom datastore that would essentially do a vertical concatenation of the datastores, instead of the horizontal concatenation done by combine.
The datastore will have 2 properties:
  1. a list of the underlying datastores
  2. index indicating which is the current underlying datastore to read from
For this datastore,
  • At the beginning, we set the index to 1 and start reading from the first ArrayDatastore a1 till it has no more data.
  • When hasdata for a1 is false, increment the index by 1 to point to the second ArrayDatastore a2.
The readall for this custom datastore would do a vertcat of the readall from all underlying datastores. This is extensible for more number of ArrayDatastores as we can just pass them to the custom datastore constructor.
Please see attached a sample VertcatDatastore.
Now, construct the VertcatDatastore using the ArrayDatastores a1 and a2 and do a readall.
vds = VertcatDatastore({a1, a2});
data = readall(vds)
NOTE: As we are seeing more similar queries, we are working on enabling vertically merging multiple datastores. That would essentially provide a means to read from the underlying datastores sequentially.
  댓글 수: 1
Odo Luo
Odo Luo 2022년 4월 13일
This solution is so simple and effective, I am ashamed I did not think of it!
Thank you for your help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing and Computer Vision에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by