views:

40

answers:

2

hi. im new in MATLAB. i think its a simple question. i want: a=1.154648126486416
to become a=1.154 and not a=1.54000000000 how do i do that without useing format('bank'). thanks.

+2  A: 

You could do this:

a = floor(a*1000)/1000;
gnovice
+1  A: 

Building on @gnovice's answer, you can format the output as a string to get rid of the extra zeros. See the sprintf documentation for all the formatting options.

str=sprintf('The result is %1.3f.',a);
disp(str)

will show "The result is 1.154." in the command prompt. Or write the string to file, etc., etc.

Doresoom