Is it possible to make different subplots with different variables on each subplot?

5 views (last 30 days)
I need to have an array of 3x3 subplots, each having a graph of the same equation, but with different different variable values for each. Is there a way to reset the variable values after each subplot? Or is there an easier way to solve this problem?

Answers (1)

Thomas Koelen
Thomas Koelen on 30 Apr 2015
Edited: Thomas Koelen on 30 Apr 2015
if you have an array like this:
a=
1 2 3 4 5
2 4 6 8 10
1 3 5 7 9
where each row represents a variable, you could do it like this:
clc
clear all
close all
a=[1 2 3 4 5; 2 4 6 8 10; 1 3 5 7 9];
s=size(a);
for iplot=1:s(1)
hold on
subplot(1,s(1),iplot)
plot(2*a(iplot,:).^2)
end
which gives you:
  2 Comments
Bilal Rambail
Bilal Rambail on 9 Mar 2021
Edited: Walter Roberson on 9 Mar 2021
sir can you explain and phrase the code for subploting two arrays elements uaing for nested loop.
eg ; A=[0 1 2 3 4 5 6 ......,23];
B=[ 7 6 5 7 8 9 7 4 3 2 4 5 6 7 8 9 7 6 4 4 7 8 4 2];
each array has 24 enteries, now i have to plot them in a singal plot with corresponding index of each element??
Walter Roberson
Walter Roberson on 9 Mar 2021
B = [ 7 6 5 7 8 9 7 4 3 2 4 5 6 7 8 9 7 6 4 4 7 8 4 2];
A = 0:length(B)-1;
plot(A, B);
hold on
text(A, B, string(A(:)));
hold off

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!