How we can do sub-plot in one graph ?
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
salim
le 24 Avr 2025
Réponse apportée : Sam Chak
le 24 Avr 2025
I want to plot a function using subplots in MATLAB. However, the function is quite long, and I need to add element-wise operators like .^, ./, and .* throughout the expression. Because of the function's length, it's difficult to manage and modify it directly. Also, due to word limits here, I can't paste the entire function. How can I simplify or structure the code to make it easier to handle and plot? Also y=0
F=real(-0.4227272727e1 * (0.1312253516e5 * exp(0.5351775227e2 * t - 0.5570000000e1 * x - 0.13708e1 * y - 0.2046600000e2) + 0.4343009244e4 * exp(0.6643795743e2 * t - 0.6670000000e1 * x - 0.6854000000e0 * y - 0.3715800000e2) + 0.620450180e5 * exp(0.3998523656e2 * t - 0.408e1 * x - 0.6854e0 * y - 0.192080e2) + 0.5409146678e5 * exp(0.1353251570e2 * t - 0.1490000000e1 * x - 0.6854000000e0 * y - 0.1258000000e1) + 0.1634390200e6 * exp(0.2645272086e2 * t - 0.2590000000e1 * x - 0.1795000000e2)) / (-0.1253256920e2 * exp(0.3998523656e2 * t - 0.408e1 * x - 0.6854e0 * y - 0.192080e2) - 0.1560910892e3 * exp(0.1353251570e2 * t - 0.1490000000e1 * x - 0.6854000000e0 * y - 0.1258000000e1) - 0.1560910892e3 * exp(0.2645272086e2 * t - 0.2590000000e1 * x - 0.1795000000e2) - 0.1560910892e3) ^ 2);

0 commentaires
Réponse acceptée
Star Strider
le 24 Avr 2025
With respect to adding element-wise operatioons to your code, use the vectorize function. The note says ‘(Not recommended)’ however it is extremely useful in some situations. I definitely do recommend it for those!
0 commentaires
Plus de réponses (1)
Sam Chak
le 24 Avr 2025
There are three variables in the function F(t, x, y). I am unsure how you would like to plot these multivariate graphs. However, you can use subplot() to create a windowed layout within a single figure.
%% declare symbolic variables
syms t x y
%% the multi-variate function, F
F = @(t, x, y) real(-0.4227272727e1 * (0.1312253516e5 * exp(0.5351775227e2 * t - 0.5570000000e1 * x - 0.13708e1 * y - 0.2046600000e2) + 0.4343009244e4 * exp(0.6643795743e2 * t - 0.6670000000e1 * x - 0.6854000000e0 * y - 0.3715800000e2) + 0.620450180e5 * exp(0.3998523656e2 * t - 0.408e1 * x - 0.6854e0 * y - 0.192080e2) + 0.5409146678e5 * exp(0.1353251570e2 * t - 0.1490000000e1 * x - 0.6854000000e0 * y - 0.1258000000e1) + 0.1634390200e6 * exp(0.2645272086e2 * t - 0.2590000000e1 * x - 0.1795000000e2)) / (-0.1253256920e2 * exp(0.3998523656e2 * t - 0.408e1 * x - 0.6854e0 * y - 0.192080e2) - 0.1560910892e3 * exp(0.1353251570e2 * t - 0.1490000000e1 * x - 0.6854000000e0 * y - 0.1258000000e1) - 0.1560910892e3 * exp(0.2645272086e2 * t - 0.2590000000e1 * x - 0.1795000000e2) - 0.1560910892e3) ^ 2);
%% making plots
figure
subplot(311)
fplot(F(t, 1, 1), [ -2, 4]), grid on
xlabel('t'), ylabel('F'), title('F(t)')
subplot(312)
fplot(F(1, x, 1), [-10, 20]), grid on
xlabel('x'), ylabel('F'), title('F(x)')
subplot(313)
fplot(F(1, 1, y), [-10, 40]), grid on
xlabel('y'), ylabel('F'), title('F(y)')
0 commentaires
Voir également
Catégories
En savoir plus sur Axis Labels dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
