How to remove NaN from data read from excel?
Show older comments
Hello all,
I am trying to solve a simple equation in matlab from the excel data. But I am getting NaN values as the data in the excel is not same in every row. How can i remove the NaN values? Please help me.
My code:
Z = readtable('Turbint_Kwsst.xlsx') ;
data = table2array(Z);
A = sqrt((2/3).*data(:,5));
O = A./data(:,4);
subplot(4,2,1)
plot(data(:,1), data(:,2), 'linewidth', 2);
hold on
plot(data(:,3), abs(O), 'linewidth', 2);
hold off
legend('Panchapaksan data-{u\prime}/U_s', 'RSM', 'Location', 'northeastoutside');
xlabel('r/L_u');
ylabel('{u\prime}/U_s');
title('At X/D = 50')
C = sqrt((2/3).*data(:,8));
Q = C./data(:,7);
subplot(4,2,2)
plot(data(:,1), data(:,2), 'linewidth', 2);
hold on
plot(data(:,6), abs(Q), 'linewidth', 2);
hold off
legend('Panchapaksan data-{u\prime}/U_s', 'RSM', 'Location', 'northeastoutside');
xlabel('r/L_u');
ylabel('{u\prime}/U_s');
title('At X/D = 60')
E = sqrt((2/3).*data(:,11));
S = E./data(:,10);
subplot(4,2,3)
plot(data(:,1), data(:,2), 'linewidth', 2);
hold on
plot(data(:,9), abs(S), 'linewidth', 2);
hold off
legend('Panchapaksan data-{u\prime}/U_s', 'RSM', 'Location', 'northeastoutside');
xlabel('r/L_u');
ylabel('{u\prime}/U_s');
title('At X/D = 70')
G = sqrt((2/3).*data(:,14));
U = G./data(:,13);
subplot(4,2,4)
plot(data(:,1), data(:,2), 'linewidth', 2);
hold on
plot(data(:,12), abs(U), 'linewidth', 2);
hold off
legend('Panchapaksan data-{u\prime}/U_s', 'RSM', 'Location', 'northeastoutside');
xlabel('r/L_u');
ylabel('{u\prime}/U_s');
title('At X/D = 80')
H = sqrt((2/3).*data(:,17));
V = H./data(:,16);
subplot(4,2,5)
plot(data(:,1), data(:,2), 'linewidth', 2);
hold on
plot(data(:,15), abs(V), 'linewidth', 2);
hold off
legend('Panchapaksan data-{u\prime}/U_s', 'RSM', 'Location', 'northeastoutside');
xlabel('r/L_u');
ylabel('{u\prime}/U_s');
title('At X/D = 90')
I = sqrt((2/3).*data(:,20));
W = I./data(:,19);
subplot(4,2,6)
plot(data(:,1), data(:,2), 'linewidth', 2);
hold on
plot(data(:,18), abs(W), 'linewidth', 2);
hold off
legend('Panchapaksan data-{u\prime}/U_s', 'RSM', 'Location', 'northeastoutside');
xlabel('r/L_u');
ylabel('{u\prime}/U_s');
title('At X/D = 100')
J = sqrt((2/3).*data(:,23));
X = J./data(:,22);
subplot(4,2,7)
plot(data(:,1), data(:,2), 'linewidth', 2);
hold on
plot(data(:,21), abs(X), 'linewidth', 2);
hold off
legend('Panchapaksan data-{u\prime}/U_s', 'RSM', 'Location', 'northeastoutside');
xlabel('r/L_u');
ylabel('{u\prime}/U_s');
title('At X/D = 110')
J = sqrt((2/3).*data(:,26));
X = J./data(:,25);
subplot(4,2,8)
plot(data(:,1), data(:,2), 'linewidth', 2);
hold on
plot(data(:,24), abs(X), 'linewidth', 2);
hold off
8 Comments
Dyuman Joshi
on 14 Jul 2022
You can remove NaN but what will you replace them with? Empty values in numeric matrices is not allowed.
Vishnuvardhan Naidu Tanga
on 14 Jul 2022
KSSV
on 14 Jul 2022
There is no data in file, so MATLAB shows up NaN's in there.
Dyuman Joshi
on 14 Jul 2022
Edited: Dyuman Joshi
on 14 Jul 2022
@KSSV, I think OP is aware of why it happens, as he mentioned this in the question statement.
"eliminate the extra empty matricies."
What do you mean? @Vishnuvardhan Naidu Tanga
Vishnuvardhan Naidu Tanga
on 14 Jul 2022
Vishnuvardhan Naidu Tanga
on 14 Jul 2022
Dyuman Joshi
on 14 Jul 2022
You can select a certain range, but if there is no data in a particular excel cell of your range, it will read it as NaN.
Otherwise you can read each column into a variable but then again, how will you perform operations if the columns don't have the same size?
Vishnuvardhan Naidu Tanga
on 14 Jul 2022
Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!