Filter löschen
Filter löschen

ploting 4 graphs for various constant values

3 Ansichten (letzte 30 Tage)
Kentman
Kentman am 17 Okt. 2014
Kommentiert: Orion am 17 Okt. 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);

Akzeptierte Antwort

Orion
Orion am 17 Okt. 2014
Bearbeitet: Orion am 17 Okt. 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 Kommentare
Kentman
Kentman am 17 Okt. 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 am 17 Okt. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graph and Network Algorithms finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by