How to solve NaN when using trapz?

32 visualizaciones (últimos 30 días)
Vishnuvardhan Naidu Tanga
Vishnuvardhan Naidu Tanga el 21 de En. de 2022
Editada: Torsten el 24 de En. de 2022
Hello all,
I am trying to do a numerical integration using trapz from a excel data. But I am getting NaN. Please provide me with some guidence.
My code:
[num data raw] = xlsread('Flowratevel.xlsx');
col_1 = num(:,1);
col_2 = num(:,2);
col_3 = num(:,3);
col_4 = num(:,4);
col_5 = num(:,5);
col_6 = num(:,6);
col_7 = num(:,7);
col_8 = num(:,8);
col_9 = num(:,9);
col_10 = num(:,10);
A1 = pi*(num(:,1)).^2;
Q1 = A1.*num(:,2);
Int1 = trapz(A1, num(:,2));
A2 = pi*(num(:,3)).^2;
Q2 = A2.*num(:,4);
Int2 = trapz(A2, num(:,4));
A3 = pi*(num(:,5)).^2;
Q3 = A3.*num(:,6);
Int3 = trapz(A3, num(:,6));
A4 = pi*(num(:,7)).^2;
Q4 = A4.*num(:,8);
Int4 = trapz(A4, num(:,8));
A5 = pi*(num(:,9)).^2;
Q5 = A5.*num(:,10);
Int5 = trapz(A5, num(:,10));

Respuesta aceptada

Torsten
Torsten el 21 de En. de 2022
Editada: Torsten el 21 de En. de 2022
[num data raw] = xlsread('Flowratevel.xlsx');
for i=1:size(num,2)
Num{i} = num(:,i)(~isnan(num(:,i)));
end
A1 = pi*Num{1}.^2;
Q1 = A1.*Num{2};
Int1 = trapz(A1, Num{2})
A2 = pi*Num{3}.^2;
Q2 = A2.*Num{4};
Int2 = trapz(A2, Num{4})
A3 = pi*Num{5}.^2;
Q3 = A3.*Num{6};
Int3 = trapz(A3, Num{6})
A4 = pi*Num{7}.^2;
Q4 = A4.*Num{8};
Int4 = trapz(A4, Num{8})
A5 = pi*Num{9}.^2;
Q5 = A5.*Num{10};
Int5 = trapz(A5, Num{10})
  3 comentarios
Torsten
Torsten el 24 de En. de 2022
Editada: Torsten el 24 de En. de 2022
I don't know why it doesn't work as above, but alternatively try
for i = 1:size(num,2)
%Num{i} = num(:,i)(~isnan(num(:,i)));
Col = num(:,i);
Num{i} = Col(~isnan(Col));
end
Vishnuvardhan Naidu Tanga
Vishnuvardhan Naidu Tanga el 24 de En. de 2022
Hello @Torsten
Thank you it worked.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!