How to induce loop index in the X-label also with changing label name at each iteration?
Show older comments
I have two programs saved in a seperate files, for instance a1.m and a2.m, and each program has the following structure. The variable a in the program has two values a=[1,2]; for which I have to run both the programs to get the two outputs for a=1 and a=2. I can apply the loop to run one program twice for a=1 and a=2 but the problem is that I also have to change the x-label name from xlabel1 to xlabel2 of every figure from 1 to 3 at each iteration. And If I apply the loop to this program to run twice, I also have to obtain six figures, three figures for a=1 and three figures for a=2. So I want to apply the loop index i on the whole program so that it runs two times with changing x-label names in each figure at each iteration and gives me two outputs for a=1 and a=2.
%a1.m......
a=1;
for i=length(a)
figure(1)
hold on
.
.
.
.
.
.
.
title('.....')
xlabel('label1');
ylabel('.....');
end
hold on
figure(2)
.
.
.
title('.....')
xlabel('label1');
ylabel('.....');
hold on
figure(3)
.
.
.
title('.....')
xlabel('label1');
ylabel('.....');
%a2.m.......
a=2;
for i=length(a)
figure(1)
hold on
.
.
.
.
.
.
.
title('.....')
xlabel('label2');
ylabel('.....');
end
hold on
figure(2)
.
.
.
title('.....')
xlabel('label2');
ylabel('.....');
hold on
figure(3)
.
.
.
title('.....')
xlabel('label2');
ylabel('.....');
1 Comment
Stephen23
on 9 Apr 2021
Repeating code like that is not a good approach. Use a loop and sprintf:
Accepted Answer
More Answers (0)
Categories
Find more on Entering Commands in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!