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

4 views (last 30 days)
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');

Accepted Answer

VBBV
VBBV on 22 Jul 2023
Edited: VBBV on 22 Jul 2023
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 Comments
VBBV
VBBV on 22 Jul 2023
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

Sign in to comment.

More Answers (0)

Categories

Find more on Graph and Network Algorithms in Help Center and File Exchange

Products


Release

R2017a

Community Treasure Hunt

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

Start Hunting!