MATLAB Answers

How and when to use sprintf disp ?....

22 views (last 30 days)
Luca on 15 Aug 2017
Edited: Luca on 16 Aug 2017
Hi guys, I m italian (excuse me for my english) and I have a question about sprintf (disp,..):
My code is :
for k=1:1:Matrice_Gruppi(1, end)
c2={Matrice_Gruppi(5, k)};
sprintf('\n %s paga %s euro.',c1{1},c2{1});
I simply would
  1. Insert with keybord a string and to save it into nomi_famiglie then
  2. To print values of nomi_famiglie and Matrice_Gruppi on command window (inizially, then I would create a interface).
I see the error:
Undefined function or variable 'sprinf'.
Could you help me please?
Thanks and bye
Luca on 16 Aug 2017
All works, thanks

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 15 Aug 2017
Edited: Image Analyst on 15 Aug 2017
There is no function sprinf(). Use sprintf(), with a "t", instead.
Or better yet, don't use cell arrays:
for k=1:1:Matrice_Gruppi(1, end)
myStrings{k} = sprintf('%s paga, %f euros.\n',...
nomi_famiglie, Matrice_Gruppi(5, k));
assuming Matrice_Gruppi is an array of doubles, not strings like you implied by using %s.
Image Analyst
Image Analyst on 16 Aug 2017
You showed in your comment above that Matrice_Gruppi is a 5 by 1 array. And Matrice_Gruppi(1,end) = 520.2000. So in your sprintf when you're trying to access Matrice_Gruppi(5, k) when k = 1,2,3,4,5,.....520, will fail because there is no columns beyond 1.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!