Automatically load a csv file from a folder

I have a database (Male_Data_Dhort_QT). Within the database I have a column called FileName which (as you assumed) has names of files that I have stored in a folder called ECGData. I have a line that randomly selects a filename.
random_MaleShortName = datasample(Male_Data_ShortQT.FileName,1)
I get a 1x1 categorical result with the name of the file.
I want to create a function that automatically gets that value and searches for the file in the ECGData folder. I'd highly appreciate any help. Thanks

4 件のコメント

Kojiro Saito
Kojiro Saito 2021 年 3 月 5 日
Do you want to get file names from ECGData folder, then run datasample function with file names as input?
Walter Roberson
Walter Roberson 2021 年 3 月 5 日
As written they want the opposite, that the database is to be the primary source for information about which files can be selected, and once a name has been chosen from the database then the file is to be opened.
Storing the names in a variable can be faster than dir() each time.
Daniela Valdez
Daniela Valdez 2021 年 3 月 5 日
No, first I randomly get a file (FileName with datasample) and I want to open that file, which it is on a different folder named ECGData
Image Analyst
Image Analyst 2021 年 3 月 5 日
What is your definition of "automatic"? And of "manual". If you have to have a line of code read in the file, is that automatic? Do you need some sort of timer that periodically gets a random filename from the database?
What is the database? Is it an actual database where you use the Database Toolbox? Or is your database just a folder of files, or a table of values?
And not sure why the filename is a categorical variable instead of a string or character array. What are the categories?

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

回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 3 月 5 日
編集済み: Walter Roberson 2021 年 3 月 5 日

0 投票

EEGDIR = '/Users/roberson/Plan9/Dhort/ECGData';
tries = 42;
found = true;
for trynum = 1 : tries
random_MaleShortName = datasample(Male_Data_ShortQT.FileName,1);
filename = fullfile(EEGDIR, string(random_MaleShortName)+".csv");
if exist(filename); found = true; break; end
fprintf('Oh, missing file "%s"\n', filename);
end
if ~found
fprintf('Bummer! No file found in %d tries! Giving up!\n', tries);
return;
end
%at this point filename refers to a file that has been verified to exist.

カテゴリ

製品

リリース

R2015b

質問済み:

2021 年 3 月 4 日

編集済み:

2021 年 3 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by