The same plotting problem, it is appear that one of the marker does not show on the graph but it should have been properly plot and the legend has shown properly too
2 ビュー (過去 30 日間)
古いコメントを表示
% Plot
figure;
plot(l_new, angular_a_n, 'b');
xlabel('Arm Length (m)');
ylabel('Angular Acceleration (rad/s^2)');
title('Angular Acceleration vs Arm Length');
grid on;
hold on;
%c
% Find the maximum angular acceleration
[max_a, i_max] = max(angular_a_n);
max_l = length(i_max);
fprintf('Maximum Achievable Angular Acceleration:%.2f rad/s^2 \n',max_a);
%d
plot(l_c, angular_a_c, 'or', 'MarkerFaceColor', 'r');
plot(max_l, max_a, 'og', 'MarkerFaceColor', 'g');
text1=sprintf('Current: %.2f rad/s^2 at length: %.2f m\n', angular_a_c, l_c);
text2=sprintf('Max: %.2f rad/s^2 at length: %.2f m', max_a, max_l);
legend({'Angular Acceleration',text1,text2});
回答 (3 件)
Walter Roberson
2024 年 9 月 6 日
The green marker is probably covered up by the legend.
[max_a, i_max] = max(angular_a_n);
angular_a_n is a vector. max of it is a scalar. The second output of max() is the location of the maximum, so it will be a scalar.
max_l = length(i_max);
The length of a scalar is 1.
plot(max_l, max_a, 'og', 'MarkerFaceColor', 'g');
max_l is 1. Your are plotting (1, max_a) . max_a is roughly 0.324 . The location (1, 0.324) happens to be under the legend box.
0 件のコメント
Jatin
2024 年 9 月 6 日
After running your code with dummy values I found that your plot does show the marker. You may want to check your logic where you are trying to calcuate the value of "max_l".
max_l = length(i_max);
This will always give the max_l as 1 becuase the length of a scalar is always 1. You may want to update your logic with the following:
max_l = l_new(i_max);
This logic correctly calculates the value of arm length at maximum speed.
Here is the code with dummy values.
l_new=0.15:0.01:2;
diam_arm = 0.05;
d_arm = 0.5;
m_hub = 0.2;
side_hub = 0.1;
m_motor = 0.3;
m_elec = 0.1;
num_l=length(l_new);
angular_a_n= [];
for i = 1:num_l
l = l_new(i);
%New Differential Thrust
delta_T_n = 0.25 * l^0.9;
% Torque
tor_n = delta_T_n * l;
% New Arm
v_arm_n = pi * (diam_arm / 2)^2 * l;
m_arm_n = d_arm * v_arm_n;
I_arma_n = (1/12) * m_arm_n * l^2;
% New Hub
I_hub_n = (1/12) * m_hub * (side_hub^2 + side_hub^2);
% New Motors
I_motor_n = 4 * m_motor * l^2;
% New Electronics
I_elec_n = 4 * m_elec * (l / 2)^2;
% New Total Moment of Inertia
I_total_n = I_hub_n + I_arma_n + I_motor_n + I_elec_n;
%New angular acceleration
angular_a_n = [angular_a_n, tor_n / I_total_n]; %#ok<AGROW>
end
l_c = 0.5; % Example current arm length
angular_a_c = 10; % Example current angular acceleration
%b
% Plot
figure;
plot(l_new, angular_a_n, 'b');
xlabel('Arm Length (m)');
ylabel('Angular Acceleration (rad/s^2)');
title('Angular Acceleration vs Arm Length');
grid on;
hold on;
%c
% Find the maximum angular acceleration
[max_a, i_max] = max(angular_a_n)
max_l = l_new(i_max)
fprintf('Maximum Achievable Angular Acceleration:%.2f rad/s^2 \n',max_a);
%d
plot(l_c, angular_a_c, 'or', 'MarkerFaceColor', 'r');
plot(max_l, max_a, 'og', 'MarkerFaceColor', 'g');
text1=sprintf('Current: %.2f rad/s^2 at length: %.2f m\n', angular_a_c, l_c);
text2=sprintf('Max: %.2f rad/s^2 at length: %.2f m', max_a, max_l);
legend({'Angular Acceleration',text1,text2});
Hope this helps!
Sam Chak
2024 年 9 月 6 日
Hi @Elisa
The idea is to reposition the legend box to a region that it doesn't block the green dot.
max_l = 1.00;
max_a = 0.32;
plot(max_l, max_a, 'og', 'MarkerFaceColor', 'g'), grid on
axis([0, 2, 0.26, 0.33])
text2 = sprintf('Max: %.2f rad/s^2 at length: %.2f m', max_a, max_l);
legend({text2}, 'location', 'southwest');
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Lighting, Transparency, and Shading についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!