Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

hey, help me fix my problem on save image .

2 visualizaciones (últimos 30 días)
fatin rasyidah
fatin rasyidah el 28 de Oct. de 2017
Cerrada: MATLAB Answer Bot el 20 de Ag. de 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 comentario
fatin rasyidah
fatin rasyidah el 28 de Oct. de 2017
here are the error . i dont understand why

Respuestas (1)

Jan
Jan el 28 de Oct. de 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 comentarios
fatin rasyidah
fatin rasyidah el 28 de Oct. de 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 el 2 de Nov. de 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.

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by