Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

are there another func.?

조회 수: 1 (최근 30일)
huda nawaf
huda nawaf 2011년 11월 1일
마감: MATLAB Answer Bot 2021년 8월 20일
hi, I don't want deal with such numbers 1.0e+009 *1.8000 are there any fun. instead of sprintf convert that no. to natural form. if I have numbers , sprintf convert all into one long string.
thanks
  댓글 수: 1
Fangjun Jiang
Fangjun Jiang 2011년 11월 1일
define "natural form"

답변 (2개)

Naz
Naz 2011년 11월 1일
type in Command Window:
format short
and the output will be of about 5 decimal digits. However, if you have such a large number as in your question, the MatLab will by default output it in exponential form (I think). Also, you dont have to use sprintf. Try this:
x=5;
disp(['This is my variable ',num2str(x)]);

Walter Roberson
Walter Roberson 2011년 11월 1일
cellstr(num2str(YourArray(:)))
will give you a cell array of strings, one value per cell entry. This should satisfy the requirement of not getting out one long string.
  댓글 수: 2
huda nawaf
huda nawaf 2011년 11월 1일
thanks
if i have this array
1.0e+009 *
1.8000 1.8049 1.8000 1.8000 1.8003
1.8000 1.8085 1.8004 1.8084 1.8074
1.8078 1.8045 1.8074 1.8076 1.8002
1.8078 1.8084 1.8084 1.8074 1.8084
1.8084 1.8084 1.8085 1.8084 1.8084
the cellstr make it vector.
please , I NEED AS ABOVE.
THEN, IS CELLSTR CONVERTING THE NUMBERS INTO STRING?
THANKS
Walter Roberson
Walter Roberson 2011년 11월 1일
cellstr() does not convert numbers in to string: num2str() does that. cellstr() prevents the output from being "one long string" as you indicated you do not want.
cellstr(num2str(YourArray))
will produce a cell array of strings, one cell entry per line of your array.
Myself, I find that a great deal of the time using the appropriate sprintf() parameters gives the output I need, as usually I am displaying to the screen where it is acceptable and desirable to have newline characters between the rows -- but I do agree that technically the result of sprintf() is always "one long string" even when it doesn't *look* that way. My guess is that you are not using \n at appropriate places in your sprintf() format, such as
sprintf( [repmat('%.4f ', 1, size(YourArray,2)-1) '%.4f\n'], YourArray.' )
But certainly there are times when you really do want different strings for every line rather than wanting newlines between rows.

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by