필터 지우기
필터 지우기

Transfer from Decimal to Percentage?

조회 수: 14 (최근 30일)
Xiao Tang
Xiao Tang 2012년 6월 25일
댓글: geopap 2016년 9월 14일
Hi guys,
I have a Matrix A =
[1 2 3
4 5 6
7 8 9]
How I can get Matrix B =
[100% 200% 300%
400% 500% 600%
700% 800% 900%]?
Sprintf might work but I don't know how to use it. Thanks in advance.
  댓글 수: 2
Walter Roberson
Walter Roberson 2012년 6월 25일
You cannot get it as a numeric matrix, as numeric matrices cannot contain '%' characters.
Xiao Tang
Xiao Tang 2012년 6월 25일
Then how can I transfer it to string or cell array? As long as there follows '%'.
I was wondering if there is a function to do this...

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2012년 6월 25일
thisfmt = [ repmat(' %.3f%%', 1, size(A,2)) '\n'];
B = sprintf( thisfmt, A.' );
B(1) = '[';
B(end) = ']';
This creates the output as a single string.
  댓글 수: 8
Xiao Tang
Xiao Tang 2012년 6월 27일
Thanks Tom! That's perfect!
geopap
geopap 2016년 9월 14일
Tom this works great!! Thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by