フィルターのクリア

how put xlsread in global variable

2 ビュー (過去 30 日間)
maria
maria 2012 年 3 月 26 日
Hello! I used function uigetfile to selected one xls file. Then I use function [text,number,d]=xlsread(...) to get text and number values from excel file. I use this functions in button (from gui) open_xls_Callback. How can I access variables text and number in other Calback (pushbutton)? How can I create global variables with [text,number])xlsread(...)?
Thanks!!

回答 (3 件)

Oleg Komarov
Oleg Komarov 2012 年 3 月 26 日
There are many ways to Share Data Among a GUI's Callbacks

Kevin
Kevin 2012 年 3 月 27 日
You have to pass your variables between the functions, not write to a 'global' variable in Matlab GUI's.
The easiest way I've found to do this is to use a data structure.
for example:
[handles.data handles.text] = xlsread(...);
and then make sure that structure 'handles' is passed to your other callback functions. If you are using defaults, it should be passing the handles structure already.

Image Analyst
Image Analyst 2012 年 3 月 27 日
See the FAQ for a variety of ways to share variables between functions: http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.3F
but it looks like the "global haters" took out the stuff in there about using global. Basically you declare your variable global in any function that you want to have access to that variable. But it's not well explained in the FAQ: http://matlab.wikia.com/wiki/FAQ#Are_global_variables_bad.3F

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by