Adding sprintf values using a loop

Dear group,
I'm trying to plot multiple subplots and adding names using loop.I tried to add a single name it works in a loop but adding multiple sprintf is snot changing the varibles ? What's the error in this?
Thanks in advance
figure
for k = 1 : 12
for a = 1:12
subplot(3,4,k);
Spec = ' A%d', 'S%d ';
caption = sprintf(Spec,k, a);
title(caption, 'FontSize', 12, 'HorizontalAlignment', 'center');
end
end

 Accepted Answer

Spec =['A%d ','S%d'];

3 Comments

Thank you for your answer Kalyan.
Only yhe A %d variable changes and S%d variable takes the static value of 12 and doesn;t change when running the code.
['A%d ','S%d']
is just a complex way of writing
'A%d S%d'
yes sir Thanks @Stephen
@Ramesh Bala Are you looking for the following
Spec ='A%d S%d';
caption=sprintf(Spec,k,k)
if not, hope you noted about the nested loops iterations.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Release

R2020a

Community Treasure Hunt

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

Start Hunting!