The Student Room Group
Reply 1
bump
Reply 2
Matlab Is Evil!!!
The freq bit maybe? I don't know what it's supposed to be.
Reply 4
freq = [0fmax]
Error: Unexpected MATLAB expression.

Well there's your problem. What are you trying to do?
Reply 5
Man, I feel your pain with this stuff.

I've wasted so many hours trying to solve problems like this...
Oh, actually I see now.

You want a new vector called freq which has the numbers between 0 and fmax?

It's because fmax is coming in as a string on input and what you're essentially saying is "Make a new array called freq and put in it the numbers between the number 0 and the word '5'", assuming you input 5 for your 'fmax' value.

You want to convert fmax to an integer before you start doing arithmetic with it.

Try...

fmaxtemp = input('Enter a maximum frequency: ', 's');
finttemp = input( 'Enter a frequency interval: ', 's');
fmax = str2num(fmaxtemp);
fint = str2num(finttemp);
freq = [0:fmax]


The str2num function will convert strings to numbers.

You could shorten it by going

fmax = str2num(input('Enter a maximum frequency: ', 's'));
fint= str2num(input( 'Enter a frequency interval: ', 's'));
freq = [0:fmax]


It does the same thing, but is just less easy to read.
Reply 7
Or just...

fmax = input('Enter a maximum frequency: ');
fint= input( 'Enter a frequency interval: ');
freq = [0:fmax]

The 's' converts tells Matlab to view it as a character string, so you're effectively converting it to characters then converting back.
That would make more sense :p: I've never really used Matlab to input user data from the keyboard so didn't really think about what the 's' was doing.

Latest

Trending

Trending