Can we use l,k,z as global variables in GUI rather than using x,y,z ?

1 回表示 (過去 30 日間)
Gayatri B
Gayatri B 2019 年 9 月 18 日
コメント済み: Gayatri B 2019 年 9 月 19 日
I'm working on image steganography code. Here I have used global l, global k, global z in the code. Is that fine or should I use global x, global y, global z ?
  2 件のコメント
Geoff Hayes
Geoff Hayes 2019 年 9 月 18 日
Gayatri - why are you using global variables at all? Please describe why you feel you need to use them...
Gayatri B
Gayatri B 2019 年 9 月 18 日
I heard that global variables have different purposes like to display image in gui like this. so I used. Can you tell me what should I use ? some part of my code is given below :
function Retrive_Callback(hObject, eventdata, handles)
global l;
h=mod(l,2);
p=zeros(1000,1000);
for x=1:1000
for y=1:1000
if(h(x,y)==1)
p(x,y)=255;
end
end
end
s=im2bw(p);
axes(handles.axes4);
imshow(s);
grid on;

サインインしてコメントする。

採用された回答

Guillaume
Guillaume 2019 年 9 月 18 日
You shouldn't be using global variables at all. There's always better ways of doing whatever it is you're doing.
As for the name of global variables, you can use whatever you want. If you do use global variables (which are a major source of bugs) I would recommend using very descriptive names rather than one letter variables.
Obviously, the name must be the same in each unit of code that uses these variables.
  3 件のコメント
Guillaume
Guillaume 2019 年 9 月 18 日
You can use the handles structure to pass data between callbacks.
See Share data among callbacks for other ways, all better than global variables.
Gayatri B
Gayatri B 2019 年 9 月 19 日
okay. I want to declare these variables before using it anywhere so I used global.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by