Combine 3 graphics into a single one
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Philippe Girard
le 22 Jan 2017
Commenté : Image Analyst
le 22 Jan 2017
Hi,
I'm trying to combine 3 graphics into a single one . First, here is my program
function graphique()
global x h f_vec i
h_vec=[0.015625,0.1,0.5];
x=linspace(0.1,2);
for i=1:3
h=h_vec(i);
f = F();
end
plot(x,f_vec)
end
function f=F()
global h x f_vec i
f= 1./(((1-x.^2).^2+h.*x.^2).^(1/2));
f_vec(i)=f;
end
I was expecting that matlab will starts with the first iteration with i=1, associate a value h=0.015625 and call the function f=F(). He calculates f into the second block with the big equation and associate all the values of f to f_vec(1) then come back to the loop "for" with i=2... After doing all 3 iterations, he would get out of the loop and plot a vector f_vec in function of x. But I get an error with f=F() because it seems like having this variable into another function his not for him consider as using it.
Anyway the goal is to get a single window combining 3 graphs. I need help this program was mostly done by a user here and I'm still unable to finish it. Is there a way to use
f_vec
as a storage for all values of the 3 iterations.
0 commentaires
Réponse acceptée
Image Analyst
le 22 Jan 2017
Why can't you just take the two lines from your function and put it into the loop.
function graphique()
global x h f_vec i
h_vec=[0.015625,0.1,0.5];
x=linspace(0.1, 2, length(j));
for i=1:3
h=h_vec(i);
f= 1./(((1-x.^2).^2+h.*x.^2).^(1/2));
f_vec(i)=f;
end
plot(x,f_vec)
end
Get rid of the F() function definition. Then you'll have just a single function that does everything your two functions used to do. Be sure to fix linspace() like I did so that it has the same number of elements as h.
4 commentaires
Image Analyst
le 22 Jan 2017
But you said using global was a required part of the solution. Like they wanted/required you to use it. Anyway, thanks for accepting.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!