How do i count numbers ending in 3
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a bunch of numbers x=[234 352 298 213 365 321 293 213], Iwant to know how to count number ending in 3. The output should be 3
0 Kommentare
Antworten (3)
Torsten
am 26 Aug. 2022
x = [234 352 298 213 365 321 293 213];
n = numel(x);
end_digit = zeros(n,1);
for i = 1:n
y = num2str(x(i));
end_digit(i) = str2num(y(end));
end
s = sum(end_digit==3)
0 Kommentare
Abderrahim. B
am 26 Aug. 2022
This:
x =[234 352 298 213 365 321 293 213] ;
xs = strsplit(num2str(x), ' ') ;
total = nnz(endsWith(xs, '3'))
0 Kommentare
Stephen23
am 26 Aug. 2022
Simple, efficient, basic mathematics:
x = [234,352,298,213,365,321,293,213];
n = nnz(mod(x,10)==3)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!