필터 지우기
필터 지우기

print average beside it's row

조회 수: 1 (최근 30일)
mohammed almakaleh
mohammed almakaleh 2020년 5월 14일
편집: mohammed almakaleh 2020년 5월 14일
Help please
hi i wrote a program that calculate the average for each row in a matrix
that the user entered what i want is to print the average beside it's row
like this :
1 2 3 4 10
1 2 3 4 10
3 4 1 2 10
but the program print like this:
1 2 3 4
1 2 3 4
3 4 1 2
10
10
10

답변 (1개)

Joe_Z
Joe_Z 2020년 5월 14일
disp() will automatically start a new line, so to print all on a single line you'll need to use s/fprintf(), in a single expression for ease. Your close, you can just delete the disp line and replace the fprintf expression with:
fprintf(' \t\t %i %i %i %i %f \n', matrix(i, :), avg);
Some more details on printing arrays can be found at https://www.mathworks.com/matlabcentral/answers/333890-how-do-i-use-fprintf-to-show-the-entire-array-in-one-ouput-statement
  댓글 수: 1
mohammed almakaleh
mohammed almakaleh 2020년 5월 14일
Is there any way to print the matrix without using (% i) for each column?

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

카테고리

Help CenterFile Exchange에서 Numeric Types에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by