MATLAB: How to add space between vector indices in an output

MATLABspaces

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')

Best Answer

  • fprintf('%d ',B(1:end-1))
    fprintf('%d]\n', B(end))