Can someone please help! I cannot plot this graph. Multiple 3 line graph.

조회 수: 4 (최근 30일)
Hi guys, i've tried to plot graph after calculation for 5x3. Unfortunately the graph plotted for last row. When recheck graph data found for 1st and 2nd row shows as 0. But on the output table has all the data.
Please help me fix it.
Only have an error as "add preallocation for speed".
here is the calulated table(Terget is for maximum Pressure)
Here is my graph
>>supposed have to show 3 staright line graph
Table for the graph...collumn 1 and 2 has no data.
here is my code. please help.
clear;
clc;
r = 0.05; %radius in meter
viscosity = [256E-3, 544E-3, 1200E-3, 3680E-3, 5440E-3]; %viscosity in pa.s
l = 0.08; %length in meter
rm = 0.075; %mean radius
N = [1000,3000,4000]; %speed in rpm
sh = 10E-6; %sh in unit meter
fprintf(' ---------------------------------------------------------------------------------------\n');
fprintf(' |Speed (RPM)\tVelocity (m/s)\t\tViscosity (Pa.s)\tMaximum Pressure(MPa) | \n ');
fprintf('---------------------------------------------------------------------------------------\n');
for i = 1:length(N)
u = ((2.*3.142.*N(i))./60)*rm;
for j = 1:length(viscosity)
ho = sh/1.4142;
pm = ((3*u*viscosity(j)*l*sh)/((2*ho)*(sh+ho)*(sh+(2*ho))))/10^6;
fprintf(' | %d\t\t\t%0.6d\t\t\t%0.6d\t\t\t%0.6d\t |\n', N(i), u, viscosity(j), pm);
end
fprintf(' ---------------------------------------------------------------------------------------\n');
end
figure;for i = 1:length(N)
end
u = ((2.*3.142.*N(i))./60)*rm;
for j = 1:length(viscosity)
ho = sh/1.4142;
pm = ((3*u*viscosity(j)*l*sh)/((2*ho)*(sh+ho)*(sh+(2*ho))))/10^6;
viscosity_pm(j,i) = pm;
end
hold on;
for i = 1:length(N)
plot(viscosity, viscosity_pm(:,i), 'DisplayName', ['Speed (RPM) = ',num2str(N(i))]);
end
xlabel('Viscosity (Pa.s)');
ylabel('Maximum Pressure (MPa)'); legend('show');

채택된 답변

VBBV
VBBV 2023년 7월 22일
편집: VBBV 2023년 7월 22일
clear;
clc;
r = 0.05; %radius in meter
viscosity = [256E-3, 544E-3, 1200E-3, 3680E-3, 5440E-3]; %viscosity in pa.s
l = 0.08; %length in meter
rm = 0.075; %mean radius
N = [1000,3000,4000]; %speed in rpm
sh = 10E-6; %sh in unit meter
fprintf(' ---------------------------------------------------------------------------------------\n');
---------------------------------------------------------------------------------------
fprintf(' |Speed (RPM)\tVelocity (m/s)\t\tViscosity (Pa.s)\tMaximum Pressure(MPa) | \n ');
|Speed (RPM) Velocity (m/s) Viscosity (Pa.s) Maximum Pressure(MPa) |
fprintf('---------------------------------------------------------------------------------------\n');
---------------------------------------------------------------------------------------
for i = 1:length(N)
u = ((2.*3.142.*N(i))./60)*rm;
for j = 1:length(viscosity)
ho = sh/1.4142;
pm = ((3*u*viscosity(j)*l*sh)/((2*ho)*(sh+ho)*(sh+(2*ho))))/10^6;
fprintf(' | %d\t\t\t%0.6d\t\t\t%0.6d\t\t\t%0.6d\t |\n', N(i), u, viscosity(j), pm);
end
fprintf(' ---------------------------------------------------------------------------------------\n');
end
| 1000 7.855000e+00 2.560000e-01 8.280140e+02 | | 1000 7.855000e+00 5.440000e-01 1.759530e+03 | | 1000 7.855000e+00 1.200000e+00 3.881316e+03 | | 1000 7.855000e+00 3.680000e+00 1.190270e+04 | | 1000 7.855000e+00 5.440000e+00 1.759530e+04 |
---------------------------------------------------------------------------------------
| 3000 2.356500e+01 2.560000e-01 2.484042e+03 | | 3000 2.356500e+01 5.440000e-01 5.278589e+03 | | 3000 2.356500e+01 1.200000e+00 1.164395e+04 | | 3000 2.356500e+01 3.680000e+00 3.570811e+04 | | 3000 2.356500e+01 5.440000e+00 5.278589e+04 |
---------------------------------------------------------------------------------------
| 4000 3.142000e+01 2.560000e-01 3.312056e+03 | | 4000 3.142000e+01 5.440000e-01 7.038119e+03 | | 4000 3.142000e+01 1.200000e+00 1.552526e+04 | | 4000 3.142000e+01 3.680000e+00 4.761081e+04 | | 4000 3.142000e+01 5.440000e+00 7.038119e+04 |
---------------------------------------------------------------------------------------
figure;
for i = 1:length(N)
u = ((2.*3.142.*N(i))./60)*rm;
for j = 1:length(viscosity)
ho = sh/1.4142;
pm = ((3*u*viscosity(j)*l*sh)/((2*ho)*(sh+ho)*(sh+(2*ho))))/10^6;
viscosity_pm(j,i) = pm;
end
end
viscosity_pm
viscosity_pm = 5×3
1.0e+04 * 0.0828 0.2484 0.3312 0.1760 0.5279 0.7038 0.3881 1.1644 1.5525 1.1903 3.5708 4.7611 1.7595 5.2786 7.0381
hold on;
for i = 1:length(N)
plot(viscosity, viscosity_pm(:,i), 'DisplayName', ['Speed (RPM) = ',num2str(N(i))]);
end
xlabel('Viscosity (Pa.s)');
ylabel('Maximum Pressure (MPa)'); legend('show');
  댓글 수: 2
VBBV
VBBV 2023년 7월 22일
you have closed the outer for loop for figures without storing the values for array to be plotted
for i = 1:length(N)
u = ((2.*3.142.*N(i))./60)*rm;
for j = 1:length(viscosity)
ho = sh/1.4142;
pm = ((3*u*viscosity(j)*l*sh)/((2*ho)*(sh+ho)*(sh+(2*ho))))/10^6;
viscosity_pm(j,i) = pm;
end
end % the end for outer for loop
Baratganthi Krishnan
Baratganthi Krishnan 2023년 7월 22일
Thank you alot for your quick support. It worked! 🤗🙂

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by