You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Compare filename to data in table
3 views (last 30 days)
Show older comments
Hi!
The attached table (datatable) has a first column containing specific ID numbers. These ID numbers belong to matching individual files. For example, the first ID number below 'ID' is 'C01'. This row of data corresponds to a file named 'IDC01sec.csv' that is saved in the same folder. For my GUI, I need MATLAB to match the ID number to the file so that it can use the data in that row for further analysis.
Any help is appreciated!
12 Comments
Ameer Hamza
on 1 May 2018
What do you mean by "match the ID number to the file"? Do you want to convert 'C01' to 'IDC01sec.csv'?
Debbie Oomen
on 1 May 2018
@Ameer Hamza, no I do not want to convert it. The C01 is the unique part of the filename IDC01sec.csv. Other files have the same ID...sec.csv format but a different ID number. I will explain further: the IDC01sec.csv file contains continuous data from multiple consecutive days, so 24 hours from day 1 to 24 hours from day 10. However, we are not interested in the complete data from those 24 hours, but only data from a specific timeframe. The attached table contains these important specific timeframes from each day that contains the actual necessary data that is needed for further analysis. So it says that C01 on day 1, has important data from 07:00 to 21:00. MATLAB needs to be able to recognize these timestamps and analyze only data between those timestamps from the IDC01sec.csv file.
Debbie Oomen
on 1 May 2018
@John BG, everything has to be done in MATLAB. It is a GUI and is supposed to be used for data analysis so I don't believe that this will work
Ameer Hamza
on 2 May 2018
You cannot refer to specific parts of a file directly. You will need to read the entire file and then search for the specific data you want. If you are worried about the overhead of reading and processing file then it is better to generate .mat files from all the csv files. MATLAB can quickly read these files and they are also ready to process.
Jan
on 2 May 2018
@Debbie: You do have the string 'C01' already and want to import the contents of the file 'IDC01sec.csv'. This sounds like all you have to do is:
str = 'C01'; % Coming from anywhere in your code
FileName = sprintf('ID%ssec.csv');
Data = csvread(FileName);
Now these data must be inserted where you need it.
Currently this advice is very vague, because the description of your problem is also. Can you post the current code and explain more exactly, what the problem is?
Debbie Oomen
on 2 May 2018
@Jan, I have attached the GUI and the code. If you open the GUI, you see three options for analyzing file. Now, these files all have the same format: 'ID...sec.csv'. Belonging to these files is a so-called diaryfile that keeps track of important timestamps for all files in 1 spreadsheet (see attachment Diaryrecord). In the first column of the spreadsheet are the ID numbers that match the filenames. I need MATLAB to recognize the specific row with timestamps that matches the filename. These timestamps are then used to analyze only that part of the ID0215.csv file
Jan
on 2 May 2018
@Debbie: The descriptions are not clear, if one does not know already, what you exactly mean:
I need MATLAB to recognize the specific row with timestamps
that matches the filename
"Recognize" can mean a variety of things.
...used to analyze only that part of the ID0215.csv file
What does this mean?
Debbie Oomen
on 2 May 2018
Okay, so for example:
filename: ID0215sec.csv contains 7 days of continuous data from the subject with that ID The Diaryrecord is a file with a row that looks like this:
ID participant: ID0215 Day1 Awake Time: 07:00 Day1 Bed Time: 22:00 Day2 Awake Time: 08:00 ........ till Day7 Bed Time
Then another row:
ID participant: ID5436 Day1 Awake Time: 06:00 Day1 Bed Time: 23:00.....
And then another row from another ID....and so on
If I want to analyze the data from ID0215sec.csv, then it needs to recognize the data times in the corresponding row in the Diaryrecord. Then it needs to exclude all the data in ID0215sec.csv that is NOT between the awake time and bed time for ALL days in the ID0215sec.csv file.
I hope this is a bit more clear and that you can help
Jan
on 3 May 2018
@Debbie: Sorry, I still do not get it.
Then it needs to exclude all the data in ID0215sec.csv that is
NOT between the awake time and bed time for ALL days in the
ID0215sec.csv file.
Exclude from what? Did you import the Diaryrecord file already? From the display in your comment it is not clear, if this is a tab separated file or an Excel file. You mentioned, that it is a "CSV" file, but there are no commas.
The description as text is too general to be understood by somebody, who is not familiar with what you want. Split the task into pieces: 1. Import the CSV file, 2. parse the fields to get the times numerically, etc. Then you do not have to struggle with details like "the CSV file...", because this step is solved already. This will simplify the descriptions automatically, because you do not have to mention the whole job, but can focus on a single step: "I have a cell string of names and want to exclude all names inside a certain numerical limit".
Do you see how breaking the job into pieces works? This will help you to write the code and to ask a specific question in the forum.
Debbie Oomen
on 4 May 2018
I have matched the diaryrecord row to the filename by using strcmpi. So if I choose file ID118sec.csv, MATLAB will find the row in the diary record belonging to this file. The diaryrecord row includes the wake and bed times for all days data is acquired. So now I need the code to identify the wake and bed times in the ID118sec.csv file and delete all other data that is not between wake and bed time.
Jan
on 5 May 2018
Okay. I still cannot imagine, what these sentences mean as Matlab code. But let's care about your problems: What is your question now? Explaining the purpose of the code by telling it as a story is rarley useful. See Tutorial: How to ask a good question .
Answers (0)
See Also
Categories
Find more on Tables 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!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)