Datastore SelectedVariableNames property is reset when doing changes to the Files property.

8 vues (au cours des 30 derniers jours)
Hi,
When changing the datastore.Files property, previous changes to the datastore.SelectedVariableNames property is reset:
ds = datastore(path,'Delimiter', ';', 'ReadVariableNames', 1); % create datastore
select_idx = ones(length(ds.SelectedVariableNames),1); % create index vector
select_idx(1)=0;
select_idx(3)=0;
ds.SelectedVariableNames = ds.SelectedVariableNames(select_idx==1); % removes the 1st and 3rd variable
ds.Files = ds.Files(cellfun(@check_file_date,ds.Files, days)); %<-- create new Files index to select some files.
% ds.SelectedVariableNames is now reset (1st and 3rd variable is back)
Is this the intended behaviour? I know that changing the Files property forces a reread of the first file, but there should be a way to persist changes to the datastore done before selecting the files. It makes sense to first create and manipulate the datastore, and then select data. This has been tested in R2015a.

Réponses (1)

Aaditya Kalsi
Aaditya Kalsi le 1 Juin 2015
This behaviour is because changing files resets the datastore. You could try changing the SelectedVariables after changing the Files property.
Does that help?
  2 commentaires
Leif Solås
Leif Solås le 2 Juin 2015
It does not really help out since the problem here is that I would like to configure the data store first, and then apply this when reading on different subsets of the files listend in the Files property. Reading the documentation on datastore I get the impression that this is the intention.
To get the best code structure it is desirable to have the opportunity to separate configuration and the data retrieval when using the datastore.
Aaditya Kalsi
Aaditya Kalsi le 16 Juil 2015
Thanks Leif. It seems like I need to understand better what you are trying to achieve. I can mention that you can work around this by storing the configured SelectedVariableNames and SelectedFormats in variables before setting files.
After setting the filenames, you can restore the saved settings.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Workspace Variables and MAT Files dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by