MATLAB Answers

Array indices must be positive integers or logical values.

3 views (last 30 days)
Matlab Noob
Matlab Noob on 1 Dec 2019
Answered: Image Analyst on 1 Dec 2019
This is my code. I'm trying to code an 8 bit butterfly fft. I am getting the error in this line: a=y_fft(pos)+y_fft(pos+Half);
close all
clc
f = 15;
fs = 200;
ts = 1/fs;
t = 0:ts:1-ts;
y = sin(2*pi*f*t);
y_fft = y(1:9); %I thought the error could be because I wasn't selecting the array properly. But if I take it 1:8, I get an error that says "Index exceeds the number of array elements (8)."
N = length(y_fft);
Half = N/2;
for stage=1:3; % stages of transformation
for index=0:2:(N-1); % series of "butterflies" for each stage
for n=0:(Half-1); % creating "butterfly" and saving the results
pos=n+index+1; % index of the data sample
a=y_fft(pos)+y_fft(pos+Half); % 1-st part of the "butterfly" creating operation
b=(y_fft(pos)-y_fft(pos+Half)); % 2-nd part of the "butterfly" creating operation
y_fft(pos)=a; % saving computation of the 1-st part
y_fft(pos+Half)=b; % saving computation of the 2-nd part
end;
end;
Half=Half/2; % computing the next "Half" value
end;

  0 Comments

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 1 Dec 2019
The error, probably the most common one we see here, is very well discussed in the FAQ: "Subscript_indices_must_either_be_real_positive_integers_or_logicals."

  0 Comments

Sign in to comment.

Tags

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!