필터 지우기
필터 지우기

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 CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by