The code works but the 1st column shows NaN and 3 numeric data is missing.
1 view (last 30 days)
Show older comments
I am coding a program that will conclude 3 different classes and group the grades in 10 group. I using readmatrix function and turns up the 1st column of the text file will become NaN and 3 numeric data was missing. How to get throught it??
clear;
clc;
data = readmatrix('hw3.txt');
a = 0;
b = 0;
c = 0;
d = 0;
e = 0;
f = 0;
g = 0;
h = 0;
j = 0;
k = 0;
for i = 1:45
if data(i) >=0 && data(i) <= 9
a = a + 1;
elseif data(i) >= 10 && data(i) <= 19
b = b + 1;
elseif data(i) >= 20 && data(i) <= 29
c = c + 1;
elseif data(i) >= 30 && data(i) <= 39
d = d + 1;
elseif data(i) >= 40 && data(i) <= 49
e = e + 1;
elseif data(i) >= 50 && data(i) <= 59
f = f + 1;
elseif data(i) >= 60 && data(i) <= 69
g = g + 1;
elseif data(i) >= 70 && data(i) <= 79
h = h + 1;
elseif data(i) >= 80 && data(i) <= 89
j = j + 1;
elseif data(i) >= 90 && data(i) <= 100
k = k + 1;
end
end
fprintf('0~9: %d\n', a);
fprintf('10~19: %d\n', b);
fprintf('20~29: %d\n', c);
fprintf('30~39: %d\n', d);
fprintf('40~49: %d\n', e);
fprintf('50~59: %d\n', f);
fprintf('60~69: %d\n', g);
fprintf('70~79: %d\n', h);
fprintf('80~89: %d\n', j);
fprintf('90~100: %d\n', k);
0 Comments
See Also
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!