Left digits
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
if I have a number such as 1234, how can I select the left 3 digits 123?
0 Kommentare
Akzeptierte Antwort
Sean de Wolski
am 14 Jun. 2011
left3 = @(x)str2double(x(1:3));
left3(num2str(1234))
Perhaps?
Or so it doesn't error on numbers < 100
left3 = @(x)str2double(x(1:min(3,length(x))));
Weitere Antworten (2)
Walter Roberson
am 14 Jun. 2011
You can do it arithmetically with something like
floor(x ./ 10.^ceil(log10(x+1)-3))
provided the values are at least 100
0 Kommentare
Siehe auch
Kategorien
Mehr zu Logical 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!