selecting region of plot for calculations

Hi
I have a signal 24 hours long. I would like to plot the signal over time sampling rate 0.97samples/sec. then select a region on that plot, have that selected region show as a sub plot. then i can press a button and do the calculations i want on it(min max,slope of decline,...) and show the results in a box next to the graph. If a new region of the original plot is selected it will erase the prevoius subplot and calculations with the new slected region and allow for new calculation. I would appriciate and input on this. I tried making a gui a few times and it gets confussing after a point and i get stuck. Thank you in advance for your help!
please let me know if further explanation is needed.
y data range 50:100

11 Kommentare

Mario Malic
Mario Malic am 28 Aug. 2020
Bearbeitet: Mario Malic am 28 Aug. 2020
You can create a function that accepts arguments (app, xmin, xmax) and do the calculation in there. For the graph part, you'll need a callback function for it. I do not remember a name for it, but there are some properties that are useful in your case, such as key pressed and key released.
After you create a callback, run the app from command window and try to change values from there, once you make it that way, you will know what you have to write in App Designer.
ALDO
ALDO am 28 Aug. 2020
Hi! Thank you for your responce. I am not familaiar with the key release call back function or how to use app designer. I will try to do some research on it and see if I am able to do it. If you could provide more details on this it would be much apprictated. thanks for your help!
Mario Malic
Mario Malic am 28 Aug. 2020
Bearbeitet: Mario Malic am 3 Sep. 2020
Sorry, I have mistaken on these callbacks, actually, for UIAxes mentioned callback does not exist. EDIT2: Actually there are, I must have looked on wrong place for properties. see Ayush's answer below.
I hope you have access to App Designer, I made a small example to get you started.
You can use a slider property of MinorTicks to set it accordingly to sampling rate values, or you can use integers as well. These sliders change the X limits of the plot, so once you are happy with the selected region you can get XMin, XMax values, and Y (XMin:XMax) and do the calculations in the function.
Add a few components of Edit field (numeric) that will obtain the results(properties) from the function.
And lastly, make a button that will call the function.
Edit: I didn't read the question correctly. You have a vector with ~90000 elements, In such case, you can try adding another way of controling XLim: Maybe 3 sliders for seconds, minutes and hours, or (a) Numeric Field(s).
Do few examples that are on the starting screen, they are really helpful.
ALDO
ALDO am 3 Sep. 2020
Thank you so much for your comment. I have been trying to work on building an app. I am able to make the elements but I cant make them respond to what i need to be done. I will explain what the app is seposed to do I would really appriciate any help on this because I am not able to imrove my code no matter how much i try.
0) I am able to load my data but its very slow due to the data size
1) I have ploted the data in 4 sub plots with linked axes
2) the axes shows only the first 15 minutes of the data set
3) I want to add a slider to scroll all 4 subplots silmuntaniously to reach the end of xaxis time scale
4) I added the option to adjust the display range according to the time range selection from the provided list, but when each option is selcted the change does not reflect on the graph
5) then the goal is to do calculations on the visible axes ( i think adding the option do have a user click the desired range would be too complex for my skillset right now)
this is my first time using a gui/app designer so I am confused where the problem is and how to make everything user friendly and fast.
I have attached the code i have so far. thanks again for all you help. I really need to get this to work so i can view my files as soon as possible. I appriciate any help on this. best,
ALDO
ALDO am 3 Sep. 2020
thank you mario for following up as well!
Mario Malic
Mario Malic am 4 Sep. 2020
Do you have access to App Designer? I have not worked with GUIDE, but I think App Designer is superior and easier to use than GUIDE
ALDO
ALDO am 4 Sep. 2020
Hi! I do have access to app designer but for some reason it was easier for me to understand gui compared to app desginer. I triesd doing the examples but still didnt help much. I learn better if theres a text I can follow with explanations. do you have any suggestions for that? thanks
Mario Malic
Mario Malic am 4 Sep. 2020
It is more of understanding about what you can do with each command/function. I started using App Designer 2 weeks ago and made a quite complex app that deals with tons of stuff.
For example we mentioned callbacks, in App designer, you just right click the field and there's an option to create a callback, everything gets written, you just have to say, what do you want to do with the value user inputs in.
Also, you don't have to press Start button from App designer to check if the program works properly, you can call the app through Command Window i.e. (app = name), and you can type commands that will be directly executed in the app.
ALDO
ALDO am 4 Sep. 2020
Thank you I will definetly take a look at it again.
Mario Malic
Mario Malic am 5 Sep. 2020
Bearbeitet: Mario Malic am 5 Sep. 2020
In case you decide for the App Designer, here's a small start.
I somehow managed to get the x and y values of plots, see the windows button up/down callback. It's not so far from what you want to do.
ALDO
ALDO am 8 Sep. 2020
Hi Mario Thank you for taking the time to make the layout for the app designer, I really appriate your help and input. I will try to see if I can work using this. All the best!

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Ayush Bansal
Ayush Bansal am 3 Sep. 2020

1 Stimme

  1. WindowButtonDown callback function is triggered when mouse button is clicked. Get the current position (i.e. (x,y)) of the pointer using CurrentPoint property of the axes to obtain the starting point of the region. Find the index (i.e. Istart) of the x using find function.
  2. WindowButtonUp callback function is triggered when mouse button is released and get the index (i.e. Iend) of the end point of the region as stated above.
  3. In the WindowButtonUp function to add new subplot change the initial plot to subplot using using UIaxes=subplot(m,n,p1,UIaxes) where UIaxes is name of the first axes. Then use ax2=subplot (m, n, p2) to add another subplot. Plot on the ax2 for the new data using plot (ax2, x(Istart:Iend), y(Istart:Iend)). Add button in the figure for the calculations.
  4. Use Slider ValueChangedFcn callback, triggered when slider is changed and get the Value property of slider to get the value of slider. Change the XData and YData property of all the plots accordingly.
  5. Add dropdown uicontrol and add a ValueChangedFcn callback function, change the XData, YData accordingly for all the plots.

4 Kommentare

ALDO
ALDO am 3 Sep. 2020
Thank you so much! this is so helpful. I will try this out and come back to ask if I have any questions if thats okay. Thanks again!
ALDO
ALDO am 3 Sep. 2020
Hi I tried to implement all the changes you suggested. I am still having some issues would you mind taking alook at the code and fixing the errors. please consider that I am new to using functions and gui so if there are many mistakes i appologize in advance. I would appriciate any input as I want to learn how to use this properly. Thank you for your help!
Ayush Bansal
Ayush Bansal am 4 Sep. 2020
I have made the necessary changes. I have added four subplots, WindowButtonDown callback, WindowButtonUp callback and slider. Callbacks can be added programmatically.
ALDO
ALDO am 4 Sep. 2020
Hi Ayush; Thank you so much for the time you took to correct the errors! I will try to go over every step and make sure to understand it fully. also If you have any suggested text for me to read to learn more about this it would be much appriciated. Thanks again for your help!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Startup and Shutdown finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 27 Aug. 2020

Kommentiert:

am 8 Sep. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by