Output result's format?
조회 수: 19 (최근 30일)
이전 댓글 표시
I am executing a great-script which has inside it another mini-scripts.
Those scripts execute mathematical operations in order to calculate and show results of differente variables.
The issue is that Matlab do show those results correctly but some of the in this strange format:
How can I solve this problem and achieve Matlab giving me the results in a normal format? I think that this doesn`t happen if I execute those mini-scripts separately and individualy. It only happens when I execute the great-script. I also have tried writing
format short
In the head of each mini-script but seems that this didn't fix the issue.
Thanks!
댓글 수: 1
Stephen23
2021년 2월 6일
The variables EVfiT and EVfiT1 are symbolic or character or possibly some custom class... they are certainly not numeric, so the format command is totally irrelevant.
채택된 답변
John D'Errico
2021년 2월 5일
These are symbolic expressions you are showing. The format command has NOTHING to do with symbolic expressions. It applies only to numeric values, thus typically double precision numbers.
X = 1 + sqrt(sym('13445664/2424536343636'))
X
format short
X
format rat
X
As you see, anything I do with format does not touch how we see X.
I cannot replicate what you did, because you show only a picture of your output. (If you really want help, then paste in the actual code, as text.)
But now, if I convert X to a double,
format short
Xd = double(X)
format rat
Xd
format long g
Xd
Now you see that format works, and it works as designed. I can turn it on and off on a whim. It applies to floating point numbers. The numbers that you show in that picture LOOK like numbers. But format does not understand symbolic expressions. It ignores them.
댓글 수: 9
Walter Roberson
2021년 2월 7일
We do not have your scripts, so we would only be able to make wild guesses.
Wild guess: You thought you were doing numeric integration, but you used int(), which is reserved for symbolic integration.
추가 답변 (1개)
darova
2021년 1월 30일
try double
a = 2;
b = 1/sym(a);
c = b/a
double(c)
댓글 수: 3
Walter Roberson
2021년 2월 6일
"format" is a command, not a local setting for functions or subroutines.
If you had a
disp('hello')
command inside a function, would you expect the output of the function to disappear from the command window when the function returned? NO -- you would recognize that disp() changes state permanently, rather than disp() being a local setting within the function. Just so, "format" changes are permanent until changed.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!