could anyone help me to solve the issue

조회 수: 3 (최근 30일)
jaah navi
jaah navi 2019년 8월 6일
편집: madhan ravi 2019년 8월 8일
I am having a matrix with values of
[1 0 0 1;
0 1 1 0]
I want to display the above matrix in thefollowing manner
[1.0000 0.0000 0.0000 1.0000;
0.0000 1.0000 1.0000 0.0000]
could anyone please help me on it.

채택된 답변

madhan ravi
madhan ravi 2019년 8월 8일
편집: madhan ravi 2019년 8월 8일
ix = [repmat('%.4f ',1,size(a,2)-1),'%.4f\n']; % where a is your matrix
fprintf(ix,a.')
% or perhaps you need
result = sprintfc('%.4f',a) % undocumented

추가 답변 (1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 8월 6일
편집: KALYAN ACHARJYA 2019년 8월 6일
result=compose('%1.4f',A)
compose here
  댓글 수: 2
jaah navi
jaah navi 2019년 8월 8일
when i run the command its stating Undefined function 'compose' for input arguments of type 'char'.
Could you please help me on this.
Adam Danz
Adam Danz 2019년 8월 8일
편집: Adam Danz 2019년 8월 8일
There are two issues here and it's important to understand why a solution is not working.
First, the matrix you provided in your question which Kalyan called "A" is numeric. So the input to compose() is numeric, not char. First you need to confirm what "A" is (see below) or just copy-paste A into a comment so we can see it.
class(A)
Second, compose() does allow for character inputs so the error you're getting could indicate that you're using a matlab release prior to 2016b which was when compose() was released.
ver()
If you are using a release prior to r2016b and your input is indeed a numeric matrix like the one in your question, you could use this below or the other answer provided here. However, KALYAN 's approach is best if you're working with r2016b.
A = [1 0 0 1;
0 1 1 0];
c = strsplit(sprintf('%.4f\n', A));
result = reshape(c(1:end-1),size(A))

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

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by