Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

hey, help me fix my problem on save image .

1 vue (au cours des 30 derniers jours)
fatin rasyidah
fatin rasyidah le 28 Oct 2017
Clôturé : MATLAB Answer Bot le 20 Août 2021
hi, i've try code suggested by Image Analyst on someone's question about how to save image. but when i've try the code , i got an error . how can i fix the error . here are the code. please help me. thanks in advance :)
function pushbutton7_Callback(hObject, eventdata, handles)
global bw; startingFolder = userpath defaultFileName = fullfile(startingFolder, '*.*'); [baseFileName, folder] = uiputfile(defaultFileName, 'Specify a file'); if baseFileName == 0 % User clicked the Cancel button. return; end fullFileName = fullfile(folder, baseFileName) imwrite(bw, fullFileName);
*bw is the result that i want to save.
  1 commentaire
fatin rasyidah
fatin rasyidah le 28 Oct 2017
here are the error . i dont understand why

Réponses (1)

Jan
Jan le 28 Oct 2017
The error message is clear: The contents of the variable bw is an empty array, but imwrite cannot write images without pixels.
I guess, the reason is in the part of the code, which should assign a value to the global variable bw. This is a typical effect of using global variables: They are hard to debug and tend to cause bugs. Perhaps any other function has overwritten the global bw by accident? Therefore it is recommended, to avoid them carefully. Better store bw in the ApplicationData of the figure, e.g. by using guidata:
% In the function where bw is calculated:
handles.bw = bw;
guidata(hObject, handles);
Then in your function use handles.bw and remove the global variables.
  2 commentaires
fatin rasyidah
fatin rasyidah le 28 Oct 2017
sorry, since i am very beginning with this matlab. i dont know what are the use of "handles"? and how to use it ? could u explain a little bit to me ?
Jan
Jan le 2 Nov 2017
"handles" is a struct, which is provided to all callbacks. This allows to share data between the callbacks.
Do not confuse the "handles" struct with handles of graphic elements like figures or uicontrol. Each graphic object has a unique "handle", a kind of address to access its contents. The handles of the GUI elements are stored in the "handles" struct, if you use GUIDE, but I'm convinced that this name is more confusing.

Cette question est clôturée.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by