Problem in plotting to the appdesigner UIAxes and showing error Reference to non-existent field 'UIAxes'.

I am incorporating my matlab code to appdesigner and having issue plot in the UIaxes. to plot the spectrum I have written the code in matlab as shown below:
%% plot spectrum
hfig = figure();
findpeaks(abs(spectrum), f_axis,...
'MinPeakProminence', 4,'Annotate', 'extents',...
'MinPeakWidth', 8, 'SortStr', 'descend');
set(gca, 'color', 'w', 'Fontsize', 10.0, 'Fontweight', 'bold')
set(gcf,'color','w')
title('FID - Metabolite frequencies','Fontsize', 12.0, 'Fontweight','bold')
xlabel('Frequency (Hz)')
ylabel('SNR (a.u.)')
xlim([-1000 500]);
% to pull out plot axis
ax = gca;
below is the code I am trying to plot the "ax" in UIAxes as shown in image. Please let me know what is wrong I am doing.
FIDs = struct;
for k = 1:numel(app.index_fid)
[FIDs(k).frequency, FIDs(k).spectrum, FIDs(k).peaks, ...
FIDs(k).location, FIDs(k).FWHM, FIDs(k).prominence,...
FIDs(k).meanAbs, FIDs(k).meanStd,ax] = ...
FID_process(sTWIX(app.index_fid(k)), ...
sTWIX(app.index_fid(k)).files);
% imshow(hfig)
plot(app.UIAxes,ax);
%plot (hx,'parent',app.UIAxes,xlabel,ylabel);
end
it is showing error in front of line plot(app.UIAxes,ax);
which is "Reference to non-existent field 'UIAxes'".

5 Comments

Is app.UIAxes the handle to the axes?
Are you doing this within AppDesigner with access to app.UIAxes?
yes it is a handle to plot FID. I am doing this within appdesigner with app.UIAxes and UIAxes is properties that correspond to app components.attached image
This will be difficult to troubleshoot remotely.
If you attach the app (you may need to put it in a zip file) with instructions on how to recreate the error, I could take a closer look.
thank you for the response. Here I have attached the app file please let me know if they are sufficient. Apprecioated if you could provide thensolution. I have been struggling since long and I am also beginner to the app design.
Thank you in advance.
You forgot instructions on how to reproduce the problem. What steps do I need to take to get the error you're seeing?

Sign in to comment.

 Accepted Answer

The first thing the LoadFileandprocessFIDButtonPushed does is delete its inputs (yikes!!).
There's almost never a reason to use clear or clc in a function. You're deleting the 'app' input which explains the error when you're trying to use plot(app.UIAxes,ax).

4 Comments

i tried this, but again all plots are outside the UIAxes. the compressed file is too big to attach here with data to process. Plesae advice me how to share it. Thank you.
Why did you choose to leave it in the code (clear, clc)? It definitely shouldn't be there.
Put a break point in your code where the plot(app.UIAxes...) command is,
Then run the function and let it stop at the break point.
Are any figures generated prior to that? If so, some other part of the function is generating the figures. For example, what's FID_process? Are the figures being generated in there?
I have copied the clear clc from the matlab code file but now deleted and run again it is working fine now. Thank you.
That's what I thought.
When copying and using code you should take some time to understand what each line generally does.
Glad I could help.

Sign in to comment.

More Answers (0)

Categories

Find more on Develop Apps Using App Designer 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!