Create a function and plot data

3 次查看(过去 30 天)
MattC
MattC 2023-2-28
移动Voss 2023-3-5
Hi All, here is what I am trying to achive:
  1. 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)
  1. .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
  2. .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:
  1. How to build a function in such a way that can work dynamically and can be grown for more than 1 variable
  2. Plot for each day with new values coming in
Can someone please help me out?
  1 个评论
MattC
MattC 2023-3-4
移动:Voss 2023-3-5
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?

请先登录,再进行评论。

回答(1 个)

Dinesh
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
  1. MATLAB documentation for writing and running event handler function
  2. MATLAB documentation for create and execute callback functions

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by