Using contourfcmap in Matlabs App Designer:

19 ビュー (過去 30 日間)
Steve
Steve 2024 年 10 月 22 日 17:14
コメント済み: Steve 2024 年 10 月 23 日 12:16
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 件のコメント
Steve
Steve 2024 年 10 月 22 日 17:27
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?

サインインしてコメントする。

採用された回答

Sahas
Sahas 2024 年 10 月 23 日 6:44
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 件のコメント
Steve
Steve 2024 年 10 月 23 日 12:16
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!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by