Using contourfcmap in Matlabs App Designer:

2 visualizaciones (últimos 30 días)
Steve
Steve el 22 de Oct. de 2024
Comentada: Steve el 23 de Oct. de 2024
Hello!
I really like the benefits of contourfcmap (Matlab Exchange) over contourf and would like to use it in Matlabs App Designer.
Unfortunately contourfcmap doesn't support the format Matlabs App Designer is using for plotting.
I need to specifically adress app.UIAxes.
works: contourf(app.UIAxes, X, Y, Z, 10)
doesn't work: contourfcmap(app.UIAxes, X, Y, Z, 10)
Is there a quick way to make contourfcmap useable for Matlabs App Designer or any workaround?
Thanks a lot in advance!
Kind Regards,
Steve
Testapp (Push button to Plot in app.UIAxes)
function ButtonPushed(app, event)
% Callback function for PlotButton
x = linspace(-2, 2, 100);
y = linspace(-2, 2, 100);
[X, Y] = meshgrid(x, y);
Z = exp(-X.^2 - Y.^2);
contour_levels = linspace(min(Z(:)), max(Z(:)), 10);
cmap = jet(length(contour_levels)-1);
cmap_lowest = [0 0 1];
cmap_highest = [1 0 0];
hc = contourfcmap_app(app.UIAxes, x, y, Z, contour_levels, cmap, ...
'lo', cmap_lowest, ...
'hi', cmap_highest, ...
'cbarloc', 'eastoutside', ...
'method', 'calccontour');
end
  1 comentario
Steve
Steve el 22 de Oct. de 2024
I changed the function so it would accept more input arguments:
contourfcmap(app.UIAxes,...)
With using 'method' 'recolor' and simply changing the implemented contourf-functions to
contourf(myaxes,...)
It now plots the contourfcmap-Plot. Unfortunately it doesn't show the typical contourfcmap-colorbar.
Can anyone help with that?

Iniciar sesión para comentar.

Respuesta aceptada

Sahas
Sahas el 23 de Oct. de 2024
Hi @Steve,
As per my uderstanding you would like to use "contourfcmap" function from MATLAB File Exchange forum in the MATLAB App Designer.
Currently the "contourfcmap" does not support the "Axes" argument like the MATLAB's "contourf" function does but you can try out the following steps:
  • Modify the function signature in the "contourfcmap.m" file to accept additional an additional input argument "ax" for axes.
  • After the "contourfcmap" supports the additional input argument, create figure and axes in MATLAB using "figure" and "axes" functions and run the "contourfcmap" with these axes.
  • Once it works with the axes in MATLAB, you can create "UI.Axes" object using MATLAB's "copyobj" function and use the "contourfcmap" to call them. Refer to the following MATLAB Answer for steps of creating UI.Axes from cartesian axes: https://www.mathworks.com/matlabcentral/answers/493099-how-can-i-convert-a-figure-into-a-uifigure
Refer to the following MathWorks documentation links for more information on axes and UIAxes:
I hope this is beneficial!
  1 comentario
Steve
Steve el 23 de Oct. de 2024
Thanks for your reply Sahas!
It's a nice workaround, but a little bit to tricky because contourfcmaps colorbar is an axes by itself and not part of the contourfcmap-axes.
I decided to use contourf, color the areas between the lines by myself using the Property FacePrims:
[~, hc] = contourf(X, Y, Z, contour_levels, 'LineColor', 'k');
drawnow; % this is important, to ensure that FacePrims is ready in the next line!
hFills = hc.FacePrims; % array of TriangleStrip objects
[hFills.ColorType] = deal('truecoloralpha'); % default = 'truecolor'
for idx = 1 : numel(hFills)
hFills(idx).ColorData(1:3) = cmap(idx,:)*255; % default=255
end
And additionally use a 2nd app.UIAxes for a colorbar similar to how contourfcmaps does it.
Thanks a lot!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by