Effacer les filtres
Effacer les filtres

ploting 4 graphs for various constant values

3 vues (au cours des 30 derniers jours)
Kentman
Kentman le 17 Oct 2014
Commenté : Orion le 17 Oct 2014
Hello, i want to write code for function x=a*exp(b), where b=0:2*pi, 'a' is positive value entered by user. This should be four times, i mean 4 values of a entered by user so 4 graphs drawn on window.
clear all; close all;
for i=1:4
a=input('write positive a:', 's') b= 0:2*pi; x=a*exp(b); subplot(2,2,i),plot(x) end
However this code doesn't work well, i mean it draws completely the same for all values of a!! and more strangely when i write a=10 it gives me an error msg:
Error using * Inner matrix dimensions must agree. x=a*exp(b);

Réponse acceptée

Orion
Orion le 17 Oct 2014
Modifié(e) : Orion le 17 Oct 2014
Hi,
you used input with a second argument 's', so a is interpreted as a string and not a number
for getting a string :
a=input('write positive a:', 's')
class(a)
for getting a number:
a=input('write positive a:')
class(a)
  2 commentaires
Kentman
Kentman le 17 Oct 2014
Thanks for your answer Orion,it works quite fine now. But is it really necessary to write class(a)? what does it serve here? Because i tried input command without class and it serves quite well!
Orion
Orion le 17 Oct 2014
glad it works.
and i wrote the command
class(a)
just so you can see the class of the variable in the command window. It has no impact on the code and you don't need to keep it. It's just a useful function to know when you analyse datas.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graph and Network Algorithms 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!

Translated by