How to add a column for data in datastore

9 ビュー (過去 30 日間)
Saif Aljanahi
Saif Aljanahi 2021 年 3 月 27 日
回答済み: Khushboo 2022 年 11 月 4 日
I have a data store that holds 2,700 files, theses files are activities such (standing, walking, lying,...and etc).
the datastore contains all these files, all files having 3 columns (acceleration of x,y,z).
I want to write a code that can add a fourth column to this datastore depends on the original file name that I have added earlier to this datastore.
I want to do this, to make labeling and prepare my data for classification.
  1 件のコメント
Anup Thapa
Anup Thapa 2022 年 10 月 31 日
Hi. I have the same issue/need. What solution worked for you in the end?

サインインしてコメントする。

回答 (1 件)

Khushboo
Khushboo 2022 年 11 月 4 日
Hello,
As datastore simply reads the data from a file to a table, you will have to write the modified table back to the datastore. This can be done using something like this:
while hasdata(currentDs)
[T, info] = read(currentDs);
% Add a new column to the end of the table
T.newCol = newColumnToBeAdded; %ensure that it is a cell array
%Write the new modified file back the table
filename = ['newfolder/modifiedfile_', num2str(info.Offset), '.csv'];
writetable(T, filename);
end
newDs = datastore('newfolder/*.csv');
Hope this helps!

カテゴリ

Help Center および File ExchangeLarge Files and Big Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by