필터 지우기
필터 지우기

How to add space between vector indices in an output

조회 수: 6 (최근 30일)
Ashlee Rogers
Ashlee Rogers 2020년 9월 26일
댓글: Ashlee Rogers 2020년 9월 26일
I am trying to find out how to make my output have spaces in between the indices of the vector...This is what I have so far, which is giving me the correct vector output:
A=input('Enter values in A in vector form:');
for i=1:length(A)
if (A(i)>0)
B(i) = A(i)^3;
else
B(i) = 0;
end
end
fprintf('The output vector is :\t[')
fprintf('%d',B)
fprintf(']\n')

채택된 답변

Walter Roberson
Walter Roberson 2020년 9월 26일
fprintf('%d ',B(1:end-1))
fprintf('%d]\n', B(end))
  댓글 수: 3
Walter Roberson
Walter Roberson 2020년 9월 26일
편집: Walter Roberson 2020년 9월 26일
Notice in the first of the two lines I posted, there is a space between the %d and the following '
apostrophe percent d space apostrophe
Ashlee Rogers
Ashlee Rogers 2020년 9월 26일
Yes, thank you! I missed that space! 😊 Very grateful to you

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by