100% found this document useful (1 vote)
871 views2 pages

How To Store Data Into AXES FIGURE USERDATA in Matlab

This document discusses storing data in the userdata property of axes figures in MATLAB. It notes that plotting resets the userdata, so the data should be stored in userdata after plotting to avoid it being empty. An example is provided where audio signal data is plotted in a figure, metadata is added to the axes, and then the data is stored in the axes' userdata property to allow accessing it from any callback. Moving the userdata assignment after plotting fixes the issue.

Uploaded by

Jans Hendry
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
100% found this document useful (1 vote)
871 views2 pages

How To Store Data Into AXES FIGURE USERDATA in Matlab

This document discusses storing data in the userdata property of axes figures in MATLAB. It notes that plotting resets the userdata, so the data should be stored in userdata after plotting to avoid it being empty. An example is provided where audio signal data is plotted in a figure, metadata is added to the axes, and then the data is stored in the axes' userdata property to allow accessing it from any callback. Moving the userdata assignment after plotting fixes the issue.

Uploaded by

Jans Hendry
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 2

[all about matlab]

January 23, 2013

HOW TO STORE DATA IN AXES FIGURE USERDATA IN MATLAB

A good Matlab Programmer while dealing with GUI will avoid using GLOBAL syntax to declare variables used in the program. The problem is Matlab will preserve much memory when you declare variables in each sub_callback. So one has to optimize using every properties that the control has. Usually, we use USERDATA property to store array or single data in Matlab GUI. So we can access the data anytime. But there is a case when we deal with userdata property of axes figure. This is not as usual as property of others control. So I need to write this article to help whether a reader face the same problem. This is not a big issue actually. What you have to do is to avoid putting the syntax before plot command. Because plot command in matlab will reset all the value in USERDATA of current axes. Please see some example below: I want to display my audio signal data to fig1 which is axes object/control. In the same sub_callback, I want to save my data into current axes USERDATA. So what I think best to do is:
h1 = handles.fig1; set(h1, 'UserData', data); plot(h1, (1:length(data))/fcuplik, data); set(h1, 'YAxisLocation', 'Right'); xlabel(h1, 'Waktu (detik)'); ylabel(h1, 'Amplitudo'); set(h1, 'Color', [0.945 0.969 0.949]); set(h1, 'XColor', [0.847 0.161 0.0]); set(h1, 'YColor', [0.847 0.161 0.0]);

this is absolutely wrong. Take a look at the row which is dash boxed. I found this is not good placement of the code. Because the final result would be an empty cell. So we have to change its placement. See below, please:
h1 = handles.fig1; plot(h1, (1:length(data))/fcuplik, data); set(h1, 'YAxisLocation', 'Right'); xlabel(h1, 'Waktu (detik)'); ylabel(h1, 'Amplitudo'); set(h1, 'Color', [0.945 0.969 0.949]); set(h1, 'XColor', [0.847 0.161 0.0]); set(h1, 'YColor', [0.847 0.161 0.0]); set(h1, 'UserData', data);

[janshendry@gmail.com]

Page 1

[all about matlab]

January 23, 2013

when I changed the order of the row, this give desired output. So I can access the content of USERDATA from any sub_callback in matlab gui. Happy try

Picture above shows you how this is work. @thankss

[janshendry@gmail.com]

Page 2

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy