From: Rimi on 1 Jul 2010 02:38 im trying to build a program where im creating a waveform signal based on the type of waveform selected (sine, sawtooth etc). The following is an initial program i wrote and its giving me the following error: >> gg='sin'; >> ll=0:0.01:10; >> sigg=gg(ll); ??? Subscript indices must either be real positive integers or logicals. so here i want the variable "gg" to change as per the user secification of the waveform also 'll' contains the length of the signal. If anyone can help, then that would be great! thank you ~Rimi
From: Wayne King on 1 Jul 2010 06:11 "Rimi " <riharimi(a)gmail.com> wrote in message <i0hd5l$87u$1(a)fred.mathworks.com>... > im trying to build a program where im creating a waveform signal based on the type of waveform selected (sine, sawtooth etc). The following is an initial program i wrote and its giving me the following error: > > >> gg='sin'; > >> ll=0:0.01:10; > >> sigg=gg(ll); > ??? Subscript indices must either be real positive integers or logicals. > > so here i want the variable "gg" to change as per the user secification of the waveform > also 'll' contains the length of the signal. > > If anyone can help, then that would be great! > thank you > ~Rimi Hi Rimi, I think you have several issues here. The one that is giving the immediate error is that MATLAB indexes from 1, not zero. So you cannot ask MATLAB to return the zero-th element of any array. gg = 'sin'; creates a character array of length 3. You should see that gg(1) is the letter s and so on. If your user is going to enter a string for a waveform and then you want to evaluate that string as a MATLAB command to return a waveform, look at the documentation for eval and evalc >>doc eval >>doc evalc Hope that helps, Wayne
From: Jan Simon on 1 Jul 2010 06:45 Dear Rimi, > >> gg='sin'; > >> ll=0:0.01:10; > >> sigg=gg(ll); gg = 'sin'; ll = 0:0.01:10; switch gg case 'sin' sigg = sin(ll); case 'sawtooth' sigg = ... end Good luck and welcome to Matlab, Jan
From: us on 1 Jul 2010 06:53 "Rimi " <riharimi(a)gmail.com> wrote in message <i0hd5l$87u$1(a)fred.mathworks.com>... > im trying to build a program where im creating a waveform signal based on the type of waveform selected (sine, sawtooth etc). The following is an initial program i wrote and its giving me the following error: > > >> gg='sin'; > >> ll=0:0.01:10; > >> sigg=gg(ll); > ??? Subscript indices must either be real positive integers or logicals. > > so here i want the variable "gg" to change as per the user secification of the waveform > also 'll' contains the length of the signal. > > If anyone can help, then that would be great! > thank you > ~Rimi a hint: help feval; help function_handle; % eg, x=0:.1:1; fun1='sin'; fun2=(a)cos; r1=feval(fun1,x); r2=fun2(x); us
From: Steven Lord on 1 Jul 2010 14:19 "Wayne King" <wmkingty(a)gmail.com> wrote in message news:i0hpjp$che$1(a)fred.mathworks.com... > "Rimi " <riharimi(a)gmail.com> wrote in message > <i0hd5l$87u$1(a)fred.mathworks.com>... >> im trying to build a program where im creating a waveform signal based on >> the type of waveform selected (sine, sawtooth etc). The following is an >> initial program i wrote and its giving me the following error: >> >> >> gg='sin'; >> >> ll=0:0.01:10; >> >> sigg=gg(ll); >> ??? Subscript indices must either be real positive integers or logicals. >> >> so here i want the variable "gg" to change as per the user secification >> of the waveform >> also 'll' contains the length of the signal. >> >> If anyone can help, then that would be great! >> thank you >> ~Rimi > > Hi Rimi, I think you have several issues here. The one that is giving the > immediate error is that MATLAB indexes from 1, not zero. So you cannot ask > MATLAB to return the zero-th element of any array. > > gg = 'sin'; > > creates a character array of length 3. You should see that gg(1) is the > letter s and so on. Correct up to here: > If your user is going to enter a string for a waveform and then you want > to evaluate that string as a MATLAB command to return a waveform, look at > the documentation for eval and evalc No. Do NOT use EVAL here. Instead, either simply call the function like you would any other function: sigg = sin(ll); or make gg a function handle to the SIN function and invoke the function using the handle. gg = @sin; sigg = gg(ll); For more information, open up the documentation in the Help Browser by typing this command at the MATLAB prompt: doc then search for the phrase "function handle". -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ To contact Technical Support use the Contact Us link on http://www.mathworks.com
|
Pages: 1 Prev: MEX in Matlab 7.10, 64 bit, Windows 7 Next: Replacing a NaN by it nanmean |