フィルターのクリア

ploting 4 graphs for various constant values

3 ビュー (過去 30 日間)
Kentman
Kentman 2014 年 10 月 17 日
コメント済み: Orion 2014 年 10 月 17 日
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);

採用された回答

Orion
Orion 2014 年 10 月 17 日
編集済み: Orion 2014 年 10 月 17 日
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 件のコメント
Kentman
Kentman 2014 年 10 月 17 日
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 2014 年 10 月 17 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by