back again, stuck again!

edited October 2011 in Science & Tech
hey guys, im working a problem where i have to make a for loop to generate 6 sub plots of a function for array [0,2] and a = [.05, .1, .2, .4, .6, 1.0]. i also am trying to plot all the lines on the same graph.

the function is 1./sqrt(((1-x.^n).^n)+(4*a.^n.*x.^n))

for some reason im only getting two graphs when i should be getting 6, as well as only two results on the combination graph. i dont know if anyone is even up but if you are, take a crack at it. here is my code:


clear all
clc
close all

A = [0.05,0.1,0.2,0.4,0.6,1.0];% vector of zeta values
n = 2; % dealing with one power
x = linspace(0,2); % An array of omega
for i = 1:6
a = A(i); % selecting a constant from the vector A in each loop
f = @(x,a) 1./sqrt(((1-x.^n).^n)+(4*a.^n.*x.^n));% creates a function with a handle
figure(1)
subplot(2,2,i) % 2 by 2 subplot 4 plots for the ith plot
plot(x,f(x,a))
xlabel('x')
ylabel() % changing the ylabel on each iteration
title()

figure(2)% Plots all curves on the same plot
color = ;
hold on
plot(x,f(x,a),color(i))
xlabel('x')
ylabel('f(x,a)')
title()
text(0,f(0,a),)
legval(i,:) = char(abs());% creates a legend string row vector for
% the ith row.The strings change in size after each iteration that is
% why ':' is used.
legend(legval) % creates the legend using legval
end

Comments

  • kryystkryyst Ontario, Canada
    edited October 2011
    Try this for some trouble shooting.
    Before outputting each graph just have it print the value of i to see if it's finishing the loop or breaking early.
  • drasnordrasnor Starship Operator Hawthorne, CA Icrontian
    edited October 2011
    I think that figure x always clears when you use figure(x). You may need to move these outside your loop.

    EDIT: MathWorks has this to say about it:
    figure(h) does one of two things, depending on whether or not a figure with handle h exists. If h is the handle to an existing figure, figure(h) makes the figure identified by h the current figure, makes it visible, and raises it above all other figures on the screen. The current figure is the target for graphics output. If h is not the handle to an existing figure, but is an integer, figure(h) creates a figure and assigns it the handle h. figure(h) where h is not the handle to a figure, and is not an integer, is an error.

    Try creating a figure handle instead of using an integer designator.
  • TushonTushon I'm scared, Coach Alexandria, VA Icrontian
    edited October 2011
    Also, read the FAQ so that your code gets formatted properly.
Sign In or Register to comment.