Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Subscript indices must either be real positive integers or logicals

Subject: Subscript indices must either be real positive integers or logicals

From: Gokul

Date: 11 Feb, 2013 10:15:12

Message: 1 of 2

Hello,

I have written a matlab program on audio processing and im getting the error : Subscript indices must either be real positive integers or logicals.

%Fourier Transform of Sound File

%Load File
file = 'C:\Program Files\MATLAB\Work\tuning_fork_A4';
[y,Fs,bits] = wavread(file);

Nsamps = length(y);
t = (1/Fs)*(1:Nsamps); %Prepare time data for plot

%Do Fourier Transform
y_fft = abs(fft(y)); %Retain Magnitude
y_fft = y_fft(1:Nsamps/2); %Discard Half of Points
f = Fs*(0:((Nsamps-1)-1))/Nsamps; %Prepare freq data for plot

%Plot Sound File in Time Domain
figure
plot(t, y);
xlabel('Time (s)');
ylabel('Amplitude');
title('Tuning Fork A4 in Time Domain');

%Plot Sound File in Frequency Domain
figure
plot(f, y_fft);
xlim([0 1000]);
xlabel('Frequency (Hz)');
ylabel('Amplitude')
title('Frequency Response of Tuning Fork A4');

and the output is:

??? Subscript indices must either be real positive integers or
logicals.

Error in ==> audiofft at 11
y_fft = abs(fft(y)); %Retain Magnitude



even for other fft function error repeats,
kindly help

Subject: Subscript indices must either be real positive integers or logicals

From: Jos (10584)

Date: 11 Feb, 2013 11:29:13

Message: 2 of 2

"Gokul" wrote in message <kfagbg$i42$1@newscl01ah.mathworks.com>...
> Hello,
>
> I have written a matlab program on audio processing and im getting the error : Subscript indices must either be real positive integers or logicals.
>
> %Fourier Transform of Sound File
>
> %Load File
> file = 'C:\Program Files\MATLAB\Work\tuning_fork_A4';
> [y,Fs,bits] = wavread(file);
>
> Nsamps = length(y);
> t = (1/Fs)*(1:Nsamps); %Prepare time data for plot
>
> %Do Fourier Transform
> y_fft = abs(fft(y)); %Retain Magnitude
> y_fft = y_fft(1:Nsamps/2); %Discard Half of Points
> f = Fs*(0:((Nsamps-1)-1))/Nsamps; %Prepare freq data for plot
>
> %Plot Sound File in Time Domain
> figure
> plot(t, y);
> xlabel('Time (s)');
> ylabel('Amplitude');
> title('Tuning Fork A4 in Time Domain');
>
> %Plot Sound File in Frequency Domain
> figure
> plot(f, y_fft);
> xlim([0 1000]);
> xlabel('Frequency (Hz)');
> ylabel('Amplitude')
> title('Frequency Response of Tuning Fork A4');
>
> and the output is:
>
> ??? Subscript indices must either be real positive integers or
> logicals.
>
> Error in ==> audiofft at 11
> y_fft = abs(fft(y)); %Retain Magnitude
>
>
>
> even for other fft function error repeats,
> kindly help

The command WHOS will show that you have a variable called fft in your workspace ...
CLEAR it before you run the code

Better still: put the code in a function m-file

~ Jos

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us