Getting an error saying "Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters"

6 views (last 30 days)
Here is my code that I have and I have checked to make sure there are correct number of parenthesis on both sides, but continues to give this error. Any help would be appreciated.
Code:
%%Root Mean Square envelope (moving average)- mean power of signal
envelope=zeros(L,4); %L= length(data)
%Window size in ms
window=50; %larger more of original signal but distortion and spikey, lower number could be flat
for i=1:4
envelope(:,i) = sqrt(movmean(((rec_signal(:,i).^2),window)));%Average according to moving window size; %sim to RMS
Unexpected ',' in parentheses. When creating a matrix, use square brackets [].
end

Accepted Answer

Image Analyst
Image Analyst on 11 Jul 2025
Edited: Image Analyst on 11 Jul 2025
You have too many parentheses. This works:
L = 21;
rec_signal = rand(L, 4);
%% Root Mean Square envelope (moving average) - mean power of signal
envelope = zeros(L,4); % L = length(data)
% Window size in ms
window = 50; % Larger more of original signal but distortion and spikey, lower number could be flat
for i = 1 : 4
envelope(:,i) = sqrt(movmean((rec_signal(:,i).^2),window)); % Average according to moving window size; %sim to RMS
end
  2 Comments
Abhinit
Abhinit on 11 Jul 2025
Yes that worked!! Thank you very much, sorry I missed the extra parenthesis on both sides. Appreciate your help.
Image Analyst
Image Analyst on 11 Jul 2025
If this Answer solves your original question, then could you please click the "Accept this answer" link to award the answerer with "reputation points" for their efforts in helping you? They'd appreciate it. Thanks in advance. 🙂 Note: you can only accept one answer (so pick the best one) but you can click the "Vote" icon for as many Answers as you want. Voting for an answer will also award reputation points.
For full details on how to earn reputation points see: https://www.mathworks.com/matlabcentral/answers/help?s_tid=al_priv#reputation

Sign in to comment.

More Answers (0)

Products


Release

R2025a

Community Treasure Hunt

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

Start Hunting!