error/warning occurs while saving the axes as .jpeg file in GUI MATLAB

1 view (last 30 days)
Hi,
I have referred this examples to save the current result as .jpeg on axes in GUI MATLAB. It save the current result of the axes in the current file, however it appeared some error/warning on the command window:
This is the code that I used in the push button callback function:
% --- Executes on button press in save_pushbutton.
function save_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to save_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
newfig1 = figure('Visible','off');
copyobj(handles.image_axes, newfig1);
new = print('-djpeg',newfig1);
saveDataName = fullfile(path1,filename1);
saveas(new,saveDataName,'jpeg');
and the error is:
Error while evaluating uicontrol Callback
Warning: Files produced by the 'jpeg' driver cannot be sent to printer.
File saved to disk under name 'figure20.jpg'.
> In graphics\private\name at 74
In print at 206
In Noninvasive_ERT_new3>save_pushbutton_Callback at 158
In gui_mainfcn at 96
In Noninvasive_ERT_new3 at 42
In @(hObject,eventdata)Noninvasive_ERT_new3('save_pushbutton_Callback',hObject,eventdata,guidata(hObject))
Error in print (line 160)
[pj, inputargs] = LocalCreatePrintJob(varargin{:});
Output argument "varargout" (and maybe others) not assigned during call to "C:\Program
Files\MATLAB\R2011b\toolbox\matlab\graphics\print.m>print".
Error in Noninvasive_ERT_new3>save_pushbutton_Callback (line 158)
new = print('-djpeg',newfig1);
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in Noninvasive_ERT_new3 (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)Noninvasive_ERT_new3('save_pushbutton_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
helpUtils.errorDocCallback('@(hObject,eventdata)Noninvasive_ERT_new3('save_pushbutton_Callback',hObject,eventdata,guidata(hObject))')
|
Error: Unexpected MATLAB expression.
Thus, could anybody help me to overcome the problem?Tq

Accepted Answer

Walter Roberson
Walter Roberson on 16 Jan 2016
You should either use print or saveas, not both together.
The only time print() can give an output is if you pass it the '-RGBImage' argument (only) in which case it is to return an RGB array that is a copy of the current figure.
  1 Comment
yasmin
yasmin on 16 Jan 2016
Hi,
I've changed the code into:
newfig1 = figure('Visible','off');
image=copyobj(handles.image_axes, newfig1);
saveas(image,'Tomogram.jpeg');
and it works successfully. But, when I changed the colormap of the image on the axes, it still saved as the jet color not as the current colormap that I have choose.
Why it was happen? and how to make it save as the curretn colormap I have choosen?

Sign in to comment.

More Answers (0)

Categories

Find more on Visual Exploration in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!