How to be able to plot multiple 3D elements in different colors with app designer on the same graphic ?
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi,
I'm having trouble plotting 3D elements of different colors with app designer. In fact, the function 'freezeColors' seems to be unefficient in app designer when I specify a UIAxes, in which I want the 3D elements to be plot, the function is opening a new figure whitout taking into account the specified UIAxes...
I'm giving you below the code I'm using in Matlab (.mat) and the figure I obtain which is what I was expecting. Below that first part you will find the code I use in app designer (.mlapp) and the figure I obtain which is totally not the one I got previously in Matlab :/
- Matlab :
%%%%%%%%%%%% Matlab Code %%%%%%%%%%%%%%
%function XXXXXXX ... open parameters (work fine)
case '1' % Tracé du pneu roulant
Vit_kmh = round(Vit*3.6*1e-3); % Conversion [mm/s] → [km/h]
z_jante1 = z_jante - enf_carc - enf_dyna;
figure(2)
surf(x, y, def_Pneu_actif') % Affichage Pneu roulant
colormap([0.3 0.3 0.3])
freezeColors % Utilisation d'une fonction permettant de différencier le profil et le pneu en mouvement
hold on
surf(x, y, Profil_actif') % Affichage profil de route sur la même figure
colormap([0.2 0.2 0.2])
title(['Vitesse : ', num2str(Vit_kmh),' Km/h |',' Taux_g_l_i_s_s_.: ', num2str(100*tau),' % | CF_i_n_s_t_.: ', ...
num2str(round(mu(compt_roul), 2))])
if Heau > 0 % Si présence d'eau, on la trace en 3D
freezeColors
hold on
surf(x, y, H_EauDyn')
colormap([0.3 0.5 1])
end
hold on
line(x_jante, min(y)*(ones(size(x_jante))), z_jante1, 'linewidth', 4, 'color', 'k')
line(x_jante, max(y)*(ones(size(x_jante))), z_jante1, 'linewidth', 4, 'color', 'k')
% view(0, 0) % Vue de profil, écrasement pneumatique
% view(25, 3) % Vue perspective 1
% view(25, 45) % Vue perspective 2
view(130, 20) % Vue perspective 3, roulant vers la gauche
% view(0, 90) % Vue de dessus, spots de contact
shading interp % Le pneu devient trop sombre sans lorsque dx est faible
hold off
axis equal
drawnow
Here is the figure I obtain and that correspond to my expectations :
- App designer :
%%%%%%%%%%%%% App designer code %%%%%%%%%%%%%%%
function Plot_Pneu3D (app,k_tau,k,axe)
str_k = strcat('WS_',num2str(k_tau),'_',num2str(k),'.mat');
load (str_k,'x','y','z_jante','enf_carc','enf_dyna','def_Pneu_actif','Profil_actif','Heau','H_EauDyn','x_jante','Vit','tau','mu');
Vit_kmh = round(Vit*3.6*1e-3); % Conversion [mm/s] → [km/h]
z_jante1 = z_jante - enf_carc - enf_dyna;
%%%figure(2);
surf(axe,x, y, def_Pneu_actif'); % Affichage Pneu roulant
hold (axe,'on'); % Keep plotting in the same UIAxes !
colormap(axe,[0.3 0.3 0.3]); %[0.3 0.3 0.3] gray
freezeColors(axe) % Utilisation d'une fonction permettant de différencier le profil et le pneu en mouvement(fonctionne pas dans app designer)
close(1); % Allows me to close the fig.1 opened by 'freezeColors' function
surf(axe,x, y, Profil_actif'); %%% Affichage profil de route sur la même figure
colormap(axe,[0.2 0.2 0.2]); % [0.2 0.2 0.2] dark gray
title(axe,['Vitesse : ', num2str(Vit_kmh),' Km/h |',' Taux_g_l_i_s_s_.: ', num2str(100*tau),' % | CF_i_n_s_t_.: ', ...
num2str(round(mu(k), 2))]);
%newcolors = [0.3 0.3 0.3; 0.2 0.2 0.2];
if Heau > 0 % Si présence d'eau, on la trace en 3D
freezeColors(axe); % Open fig. 1 instead of pointing the target 'axe'
close(1); % Allows me to close the fig.1 opened by 'freezeColors' function
hold (axe,'on')
surf(axe,x, y, H_EauDyn');
colormap(axe,[0.3 0.5 1]);% [0.3 0.5 1] blue
%newcolors = {'#77AC30','#7E2F8E','#D95319'}; % Other method I tried but doesn't work...
end
%mymap = [0.2 0.2 0.2;0.3 0.5 1;0.3 0.3 0.3]; % Not doing what I want
%colormap(axe,mymap);
%colororder(axe,newcolors)
hold (axe,'on')
line(axe,x_jante, min(y)*(ones(size(x_jante))), z_jante1, 'linewidth', 4, 'color', 'k');
line(axe,x_jante, max(y)*(ones(size(x_jante))), z_jante1, 'linewidth', 4, 'color', 'k');
% view(0, 0) % Vue de profil, écrasement pneumatique
% view(25, 3) % Vue perspective 1
% view(25, 45) % Vue perspective 2
view(axe,app.RotationXKnob.Value,app.RotationYKnob.Value) % Vue perspective 3, roulant vers la gauche
% view(0, 90) % Vue de dessus, spots de contact
shading (axe,'interp'); % The tyre become to dark whitout when parameter dx is low
axis (axe,'equal');
hold (axe,'off')
drawnow;
end
Here is the figure I obtain using app designer and that is far frome what I plot with matlab... :
PS : I also tried different method in app designer using 'colororder()','surf(ax,x,y,z,C)' C = Colormap. I also tried to remove some hold (app.UIAxes,'on') and to work with only the first of them but it doesn't seems to affect the results...
I really think the problem is coming from the 'freezeColors' function which was not implemented by Matlab but developed by a matlab user to solve a common problem.
Many thanks to those who will take of their time to help me.
0 Commenti
Risposte (1)
Infinite_king
il 8 Dic 2023
Modificato: Infinite_king
il 8 Dic 2023
Hi Nel Pagano,
I understand that you are attempting to plot different surfaces on the same axis with different colormaps using 'freezeColors' in App Designer, but it seems that this approach is not yielding the expected results.
The 'freezeColors' function, not being an in-built feature, cannot be guaranteed to work in all situations or with later releases. Since it was written in 2005, it’s possible that it will not work as expected in R2021a or R2021b release. For more information on 'freezeColors,' please refer to the following link
To plot surfaces with different color maps on the same axis, you can specify the surface color information while creating the figure. Refer the below code snippet,
% Sample data
[X, Y, Z1] = peaks(100);
Z1 = Z1 + 10;
Z2 = Z1 + rand(1,100) + 10;
% Create figure
figure;
ax = gca;
% setting every point to red color [1 0 0]
c = zeros([100,100,3]);
c(:,:,1) = 1;
c(:,:,2) = 0;
c(:,:,3) = 0;
% Plot the first surface
surf(ax, X, Y, Z1,c);
hold on; % Keep the current axis
% setting every point to green color [0 1 0]
c = zeros([100,100,3]);
c(:,:,1) = 0;
c(:,:,2) = 1;
c(:,:,3) = 0;
% Plot the second surface
surf(ax, X, Y, Z2,c);
hold off; % Release the hold on the axis
For more information on ‘surf’ function, refer the following MATLAB documentation,
Hope this is helpful.
0 Commenti
Vedere anche
Categorie
Scopri di più su Surface and Mesh Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!