Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

hey, help me fix my problem on save image .

2 Ansichten (letzte 30 Tage)
fatin rasyidah
fatin rasyidah am 28 Okt. 2017
Geschlossen: MATLAB Answer Bot am 20 Aug. 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 Kommentar
fatin rasyidah
fatin rasyidah am 28 Okt. 2017
here are the error . i dont understand why

Antworten (1)

Jan
Jan am 28 Okt. 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 Kommentare
fatin rasyidah
fatin rasyidah am 28 Okt. 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 am 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.

Diese Frage ist geschlossen.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by