How to write a For loop for the last characters vector names
Show older comments
I have the following variables that I want to plot:
t=1:1:20
P_eA
P_eZ
C_eA
C_eZ
I can make a subplot by writing
figure(1)
subplot(2,1,1)
plot(t, P_eA)
subplot(2,1,2)
plot(t, C_eA)
figure(2)
subplot(2,1,1)
plot(t , P_eZ)
subplot(2,1,2)
plot(t, C_eZ)
However, I'm wondering if there is a way to write a for loop where I can loop over the last characters of each vector. What I am thinking of is something like
char = char('eA','eZ');
for i=1:2
figure(i)
subplot(2,1,1)
plot(t, P_{char(i,:)})
subplot(2,1,2)
plot(t, C_{char(i,:)})
end
end
Accepted Answer
More Answers (0)
Categories
Find more on Pie Charts 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!