How to add space between vector indices in an output

9 visualizzazioni (ultimi 30 giorni)
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')

Risposta accettata

Walter Roberson
Walter Roberson il 26 Set 2020
fprintf('%d ',B(1:end-1))
fprintf('%d]\n', B(end))
  3 Commenti
Walter Roberson
Walter Roberson il 26 Set 2020
Modificato: Walter Roberson il 26 Set 2020
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 il 26 Set 2020
Yes, thank you! I missed that space! 😊 Very grateful to you

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by