Mohamadjavad
Mohamadjavad

Reputation: 31

How to change obtained format

I've got a problem changing my code result. The main problem is when I run the code, it works very well, and the final results are accurate. However, as you can see it's like a division of 2 big numbers. Please help me out how to change the formation of the results. I have to say that I've already used **format command ** and didn't get anything. the result I want is something like :

sigma=156.45e+6;

Thanks.

enter image description here

Upvotes: 0

Views: 80

Answers (2)

Emaad Shamsi
Emaad Shamsi

Reputation: 112

The format command isn't what you need here I think. If these values were generated using the symbolic toolbox, then they tend to remain as whole fractions, and in order to change this, you simply need to run the following code either in your script or in the command window:

sympref('FloatingPointOutput',true);

This will produce the values you are looking for. Alternatively you can cast the values you have to a double using the following code:

ans = double(ans);
sigma1 = double(sigma1);
sigma2 = double(sigma2);

Upvotes: 1

Max
Max

Reputation: 4045

You must have set the command window format to long some time ago as this is not the usual behavior.

You can change this simply by typing to the command window. The defaults are:

format shortEng % number representation
format compact % line spacing

BTW, you can get your current setting with this command

get(0,'Format')

However, changing the format only applied to your current session (until you close MATLAB). Therefore it is odd that you ask. If it persists to be changed, someone must have fiddled with the preference

The specified format applies only to the current MATLAB session. To maintain a format across sessions, choose a Numeric format or Numeric display option in the Command Window Preferences.

Upvotes: 0

Related Questions