Plot Function not displaying all points in data set

조회 수: 6 (최근 30일)
Sam Blake
Sam Blake 2023년 10월 11일
댓글: Walter Roberson 2023년 10월 12일
Hello I am trying to plot two arrays of 13x1, one in the x-axis and the other in the y-axis, when I go to plot these, I am only recieving 7 out of the 13 data points. The two 13x1 doubles are velocity35 or velocity60 as the y and plotted against it is radius, in the x. I have attached the code as well as the excel file the data comes from. I really have no idea why im not getting the full dataset, I have tryed messing with the x and y limits of the axis but apart from that Im stumped. If anyone can spot why when you plot make these plots, I am only getting 7 data points instead of the full 13 points that are held within each variable, Id really appreciate you. Thanks!
clc;clear; close all
x = importdata('TFL Lab 1.xlsx');
Warning: File contains uninterpretable data.
rho_air = 0.0765; %lb/ft cubed
%draw values from spreadsheet
Height60 = x.data(3:15,4); Dynamic_Pressure60 = x.data(3:15,7) ;
Index in position 1 exceeds array bounds.
Height35 = x.data(16:28,4); Dynamic_Pressure35 = x.data(16:28,7);
%converting values to radii and velocity
radius = [2.365/2 2.262/2 2.148/2 2.019/2 1.865/2 1.665/2 1.183/2 1.665/2 1.865/2 2.019/2 2.148/2 2.262/2 2.365/2]'
velocity60 = 60 ./ (pi.*radius.^2); %calculating velocity by Q=V*A->V=Q/A
velocity35 = 35 ./ (pi.*radius.^2);
%Plotting Theoretical Curves
U35_laminar = max(velocity35)*(1-(radius/1.25).^2);
U35_turbulent = max(velocity35)*(1-(radius/1.25).^(1/8));
U60_laminar = max(velocity60)*(1-(radius/1.25).^2);
U60_turbulent = max(velocity60)*(1-(radius/1.25).^(1/8));
%low flow rate velocity profile
figure(1)
hold on
plot(radius,velocity35,'r')
plot(radius,U35_laminar,'g')
plot(radius,U35_turbulent,'b')
legend('Observed Velocity','Theoretical Laminar Curve','Theoretical Turbulent Curve')
title('35 GPM Velocity Profile versus Theoretical Curves' )
xlabel("Radius in inches") ; ylabel("Velocity in inches per minute")
hold off
%high flow rate velocity profile
figure(2)
hold on
plot(radius,velocity60,'r')
plot(radius,U60_laminar,'g')
plot(radius,U60_turbulent,'b')
legend('Observed Velocity','Theoretical Laminar Curve','Theoretical Turbulent Curve')
title('60 GPM Velocity Profile' )
xlabel("Radius in inches") ; ylabel("Velocity in inches per minute")
hold off
  댓글 수: 1
Sam Blake
Sam Blake 2023년 10월 12일
One thing for clarification: This code was ran in Matlab 2023a, i have that entered into the question information but it wont change.

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

채택된 답변

Walter Roberson
Walter Roberson 2023년 10월 11일
You have duplicate radius values. Also, the radius values are not sorted.
OFF = @(R)R-1;
x.data = readmatrix('TFL Lab 1.xlsx');
rho_air = 0.0765; %lb/ft cubed
%draw values from spreadsheet
Height60 = x.data(OFF(3:15),4); Dynamic_Pressure60 = x.data(OFF(3:15),7) ;
Height35 = x.data(OFF(16:28),4); Dynamic_Pressure35 = x.data(OFF(16:28),7);
%converting values to radii and velocity
radius = [2.365/2 2.262/2 2.148/2 2.019/2 1.865/2 1.665/2 1.183/2 1.665/2 1.865/2 2.019/2 2.148/2 2.262/2 2.365/2]' ;
numel(radius)
ans = 13
numel(unique(radius))
ans = 7
velocity60 = 60 ./ (pi.*radius.^2); %calculating velocity by Q=V*A->V=Q/A
velocity35 = 35 ./ (pi.*radius.^2);
%Plotting Theoretical Curves
U35_laminar = max(velocity35)*(1-(radius/1.25).^2);
U35_turbulent = max(velocity35)*(1-(radius/1.25).^(1/8));
U60_laminar = max(velocity60)*(1-(radius/1.25).^2);
U60_turbulent = max(velocity60)*(1-(radius/1.25).^(1/8));
%low flow rate velocity profile
figure(1)
hold on
plot(radius,velocity35,'r-*')
plot(radius,U35_laminar,'g-*')
plot(radius,U35_turbulent,'b-*')
legend('Observed Velocity','Theoretical Laminar Curve','Theoretical Turbulent Curve')
title('35 GPM Velocity Profile versus Theoretical Curves' )
xlabel("Radius in inches") ; ylabel("Velocity in inches per minute")
hold off
%high flow rate velocity profile
figure(2)
hold on
plot(radius,velocity60,'r-*')
plot(radius,U60_laminar,'g-*')
plot(radius,U60_turbulent,'b-*')
legend('Observed Velocity','Theoretical Laminar Curve','Theoretical Turbulent Curve')
title('60 GPM Velocity Profile' )
xlabel("Radius in inches") ; ylabel("Velocity in inches per minute")
hold off
nnz(~isfinite(velocity35))
ans = 0
nnz(~isfinite(U35_laminar))
ans = 0
nnz(~isfinite(U35_turbulent))
ans = 0
nnz(~isfinite(velocity60))
ans = 0
nnz(~isfinite(U60_laminar))
ans = 0
nnz(~isfinite(U60_turbulent))
ans = 0
  댓글 수: 2
Sam Blake
Sam Blake 2023년 10월 12일
Thank you for pointing out the duplicate values! They are distances so Im able to represent some as negatives. Im not really sure what you mean by the values are not sorted.
Walter Roberson
Walter Roberson 2023년 10월 12일
OFF = @(R)R-1;
x.data = readmatrix('TFL Lab 1.xlsx');
rho_air = 0.0765; %lb/ft cubed
%draw values from spreadsheet
Height60 = x.data(OFF(3:15),4); Dynamic_Pressure60 = x.data(OFF(3:15),7) ;
Height35 = x.data(OFF(16:28),4); Dynamic_Pressure35 = x.data(OFF(16:28),7);
%converting values to radii and velocity
radius_differences = [2.365/2 2.262/2 2.148/2 2.019/2 1.865/2 1.665/2 1.183/2 1.665/2 1.865/2 2.019/2 2.148/2 2.262/2 2.365/2]' ;
radius = cumsum(radius_differences);
numel(radius)
ans = 13
numel(unique(radius))
ans = 13
velocity60 = 60 ./ (pi.*radius.^2); %calculating velocity by Q=V*A->V=Q/A
velocity35 = 35 ./ (pi.*radius.^2);
%Plotting Theoretical Curves
U35_laminar = max(velocity35)*(1-(radius/1.25).^2);
U35_turbulent = max(velocity35)*(1-(radius/1.25).^(1/8));
U60_laminar = max(velocity60)*(1-(radius/1.25).^2);
U60_turbulent = max(velocity60)*(1-(radius/1.25).^(1/8));
%low flow rate velocity profile
figure(1)
hold on
plot(radius,velocity35,'r-*')
plot(radius,U35_laminar,'g-*')
plot(radius,U35_turbulent,'b-*')
legend({'Observed Velocity','Theoretical Laminar Curve','Theoretical Turbulent Curve'}, 'Location', 'best')
title('35 GPM Velocity Profile versus Theoretical Curves' )
xlabel("Radius in inches") ; ylabel("Velocity in inches per minute")
hold off
%high flow rate velocity profile
figure(2)
hold on
plot(radius,velocity60,'r-*')
plot(radius,U60_laminar,'g-*')
plot(radius,U60_turbulent,'b-*')
legend({'Observed Velocity','Theoretical Laminar Curve','Theoretical Turbulent Curve'}, 'Location', 'best');
title('60 GPM Velocity Profile' )
xlabel("Radius in inches") ; ylabel("Velocity in inches per minute")
hold off
nnz(~isfinite(velocity35))
ans = 0
nnz(~isfinite(U35_laminar))
ans = 0
nnz(~isfinite(U35_turbulent))
ans = 0
nnz(~isfinite(velocity60))
ans = 0
nnz(~isfinite(U60_laminar))
ans = 0
nnz(~isfinite(U60_turbulent))
ans = 0

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Choose and Parameterize Blocks에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by