Using a for loop to subplot graph parabolas?
Show older comments
I'm new to matlab and need some help with an assignement. I'm being asked to use a for loop to create a subplot with 12 graphs. I have been given a matrix (called coeffs) that is 3X12, column 1 has a data, column 2 has b data and column 3 has c data. The parabola function is y= a*x.^2+b*x+c. In a seperate tab that has been saved I said:
function y = parabolafx(x,a,b,c)
y= a*x.^2+b*x+c;
In my plot tab I have:
figure
x=-5:.1:5
for a=1:12
ylim([-100 100])
subplot(4,3,a)
bah=parabolafx(x,a,b,c)
plot(x,bah)
end
What I'm trying to do is have one parabola per subplot. In this case I have 12 in each of the 12 subplots. A, b and c were all created by giving each variable its own row from the given data.
I want the for loop to run through and give me one parabola per subplot and I want it to pull a, b and c from a given set of data called "coeffs".
I recognize that I am very lost. Please help.
Accepted Answer
More Answers (1)
Fucntion part:
function y = parabolafx(x,a,b,c)
y= a*x.^2+b*x+c;
end
you need ot initialize the value of b and c. I have initilized randomly.
figure(1)
b=10;
c=2;
x=-5:0.1:5;
for a=1:12
ylim([-100 100])
subplot(4,3,a)
bah=parabolafx(x,a,b,c);
plot(x,bah)
end
Categories
Find more on Subplots 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!