Azzera filtri
Azzera filtri

ploting 4 graphs for various constant values

3 visualizzazioni (ultimi 30 giorni)
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);

Risposta accettata

Orion
Orion il 17 Ott 2014
Modificato: Orion il 17 Ott 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 Commenti
Kentman
Kentman il 17 Ott 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 il 17 Ott 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Graph and Network Algorithms in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by