Hi @Stephen23, thanks for helping me with :https://www.mathworks.com/matlabcentral/answers/1920035-how-to-loop-over-a-structure-in-matlab?s_tid=srchtitle. I am trying to build a function around this and fetch the data as well whenever there is a new data. Can you please help me if this is possible?
Create a function and plot data
4 次查看(过去 30 天)
显示 更早的评论
Hi All, here is what I am trying to achive:
- A function which takes the input as 2 folder names and then there are .mat files for each day inside of second folder
Example: Function (Main_Folder,Sub_Folder,Day1)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1310545/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1310550/image.png)
- .mat files are for a day each so for this function what I am trying to do is to pick a new file that comes into the folder. Example: Once the data for Day1, Day2 is taken already and today comes a new file Day3 it needs to be picked by the function not Day1 and Day2 again
- .mat files are a nested 1x1 struct like this
Day1.Name1.Table1 = array2table(rand(7,5));
Day1.Name1.Table2 = array2table(rand(7,5));
Day1.Name1.Table3 = array2table(rand(7,5));
3. Inside of these Tables: 1,2,3. To access the Tables I use this code
C = struct2cell(S);
T = [C{:}]
T1 = vertcat(T.Table1)
T2 = vertcat(T.Table2)
T3 = vertcat(T.Table3)
4. Then I do a comparison for one of the variable from each of these tables and get the details in a different table
Name1_T1 = T1(strcmp(T1.Var1, 'A'), :);
Name1_T2 = T2(strcmp(T2.Var1, 'A'), :);
Name1_T3 = T3(strcmp(T3.Var1, 'A'), :);
5. Then I get a value for variable2. For this variable I would like to append the value for each day's file which I haven't figured out yet. So, let's say Variable2 had value of 40 for day1, then 50 for day2 and 60 for day3 and so on
Name1_T1_Var2 = Name1_T1.Var2;
Name1_T1_Time = Name1_T1.Time;
6. Finally, I am trying for this function to build like a trent plot which will have value for each day
plot (Name1_T1_Time,Name1_T1_Var2)
7. So, basically I am trying to build a function that takes these inputs and dynamically pick each file that comes every day in the folder and then plot the data for Variable 2 (One point for each day - plot should still have previous day's value but also able to append new day's value)
Here is what I am not able to figure out:
- How to build a function in such a way that can work dynamically and can be grown for more than 1 variable
- Plot for each day with new values coming in
Can someone please help me out?
回答(1 个)
Dinesh
2023-3-2
Hello!
As per my understanding you want to execute a function whenever new data i.e., day(n) file comes in.
This is a case of an event and whenever the event occurs you can trigger a function.
So, you can write a custom event handler and, in that call-back, specify what all things you want to do.
You can refer the following MATLAB documentation for more details
- MATLAB documentation for writing and running event handler function
- MATLAB documentation for create and execute callback functions
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!