# I have a code but it keep saying "invalid expression. when calling a function or indexing a variable, use parentheses. otherwise check for mismatched delimiters.

2.749 views (last 30 days)
Roolientha Denaud on 15 Nov 2018
Commented: Walter Roberson on 29 Nov 2022
F=[];
A=[];
for f=0:200:1800
F =[F,f]; %in HZ
f0 = 500;% in Hz
f1= 1500;% in Hz
N = 20;
a = 0:5:25
a= abs((a*sin[pi(f-f0)*N]))/ (sin[pi(f-f0)]))+ abs((a*sin[pi(f-f1)*N]))/ (sin[pi(f-f1)]));
A= [A, a];
end
plot (F, A)
Walter Roberson on 29 Nov 2022

Luna on 15 Nov 2018
Edited: Luna on 15 Nov 2018
Hi Roolientha,
Your expression is invalid because you are calling a function sin with brackets not paranthesis.
sin[..] %check and correct them with paranthesis
sin(..) %because sin is a function like abs,plot,etc
Walter Roberson on 4 Oct 2022
MATLAB never uses [] for indexing, only for constructing lists and arrays. Indexing is always ()

Rik on 15 Nov 2018
Edited: Rik on 15 Nov 2018
You are using square brackets for the sin function, instead of parentheses. Also, you were missing a lot of * signs. You should check if the four constituents are indeed what you need in the line below.
a= abs((a*sin(pi*(f-f0)*N))) / sin(pi*(f-f0)) + abs((a*sin(pi*(f-f1)*N))) / sin(pi*(f-f1));
You have another problem here: you are trying to plot A against F, but A will have 6 values for each value of F, because of that first assignment of a.
You could speed this up by first fixing the dynamic growth of these vectors by pre-allocating them, and it should also be possible to remove the loop entirely once you have code that does what you intend to do.
##### 2 CommentsShowHide 1 older comment
Rik on 15 Nov 2018
Have you copied the line exactly as I posted it? Because for me it doesn't error at that line. I do have an error when plotting, because there you haven't explained how you want to extend F to have enough values. The code below assumes you want to repeat the values of F.
F=0:200:1800;%in HZ
f0 = 500;% in Hz
f1= 1500;% in Hz
N = 20;
a = 0:5:25;
A=zeros(numel(a),numel(F));
for n=1:numel(F)
f=F(n);
a= abs((a*sin(pi*(f-f0)*N))) / sin(pi*(f-f0)) + abs((a*sin(pi*(f-f1)*N))) / sin(pi*(f-f1));
A(:,n)=a;
end
plot (F, A)

Steven Lord on 15 Nov 2018
If you're editing this code in an editor other than the MATLAB Editor, I advise you to copy and paste it into the MATLAB Editor. If you have Code Analyzer enabled in the Preferences (it is enabled by default) you should see a red square in the upper-right corner of the Editor window and several colored lines (three orange, one red) below it. Orange lines indicate places where your code should work, but Code Analyzer has a suggestion that may improve its robustness and/or performance. Red lines indicate lines of code where its analysis indicates errors that will prevent your code from running at all. Clicking on the red line brings the cursor to the line in question, where the suspected error should be underlined.
If you hover over the underlined suspected error (or warning), you will receive some additional information that may help you understand the suggestion or error. In this case, once I fixed the sin[...] sections there is still an error. Counting, you have mismatched parentheses. Here I've written numbers below the locations of the parentheses in your code. Everywhere I see a ( I add 1 to the number, and everywhere I see a ) I subtract 1.
a= abs((a*sin(pi(f-f0)*N)))/ (sin(pi(f-f0))))+ abs((a*sin(pi(f-f1)*N)))/ (sin(pi(f-f1))));
12 3 4 3 210 1 2 3 210*
The * indicates -1, where I saw more closing parentheses than opening parentheses. Delete that ) and continue counting on that line of code.
Merve Özkanat on 3 Oct 2022
Hi I get the same error, could you help me please?
I want to create a yxoordinat vector [11x1] with values from a vector d.
d is a vector with 363 values.
d(afg)=dr; % d is a [363,1] vector with values.
ycoordinat=zeros(11,1);
for i=56:66
for s=1:11
ycoordinat[s,1]=d((i-1)*3+1) % d((i-1)*3+1) is the value that should be put into a vector.
end
end
But it says ''Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters''.

Aya Nabil on 19 May 2020
Edited: Aya Nabil on 19 May 2020
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters
what's is the problem?
it always shows me this comment for this code
Line: 1 Column: 23
[t,c]=ode45('prob5_16',[0,6],[0.2]);
clinear=0.2+0.111*(1-exp(-t/1.11));
plot(t,c,t,clinear)gridxlabel('time')ylabel('concentration')>>title('Solution for Problem 5.16');
Rik on 4 Oct 2022
You're using square brackets instead of parentheses.

Tahlia Jones on 20 Mar 2021
[2*3^12[cos140+sin140]/(5+3i)^3(2+3i);-(3-5i)3/25[cos-60sin-60]]
Walter Roberson on 20 Mar 2021
MATLAB has no implied multiplication. You have to put in every multiplication operator.
Also in MATLAB, function calls have to have their parameters in () such as sin(pi/3)
The MATLAB sin and cos operations are in radians but there is sind() and cosd()
Remember to put in () around denominators that involve expressions A/B*C is (A/B)*C not A/(B*C)

ali sh on 31 Jan 2022
mu=mu0*(1+omega*(3-(n2)^2);
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched
delimiters.
Steven Lord on 31 Jan 2022
You have three left parentheses ( but only two right parentheses ). Thus you have a mismatch in your parentheses. You need one more ) but where to put it depends on what you're trying to compute.

Jobin Geevarghese Thampi on 17 Mar 2022
Edited: Walter Roberson on 17 Mar 2022
functiom k=summa(n)
[row col]=size(n);
k=0;
for ii=1:row
for jj=1:col
if (ii,jj)>=5 && (ii,jj)<=18
k=k+n(ii,jj);
end
end
end
File: summa.m Line: 6 Column: 15
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check
for mismatched delimiters.
##### 2 CommentsShowHide 1 older comment
Walter Roberson on 17 Mar 2022
if n(ii,jj)>=5 && n(ii,jj)<=18

Kamilu Sanusi on 2 May 2022
Edited: Walter Roberson on 2 May 2022
Hello please I am having a similar problem, i need assistance please. What I keep getting is "Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters"
and is pointing to Line 2 column 35
Here is the code:
clear all
clc
% User Interface pop-up window
prompt=('Power Input_Bus1 [p.u.]:','Z_1 [p.u.]:','Z_12 [p.u.]:','Load_Bus2:','V2:','P.U. MVA Base:');
dlg_title='Power Flow Analysis';
defaultans =('1.06+0i','6i','0.2i','1.6+0.20i','1+0i','100');
num_lines = [ones(size(defaultans')) ones(size(defaultans'))*50];
% Reading all inputs and change string to numeric value
% ****************************%
pubase = str2num(answer(6)); % PU MVA base
% Variales declared
G1= 1/Z_1 % Self reactance
y12 = 1/Z_12
% Identify load P (real) and Q (imag) value
s2 = -1*L_B2,
p2 = real(s2);
q2 = imag(s2);
% Create the bus admittance matrix
y = [(G1+y12) -(y12);-(y12) (y12)];
% Load flow calculation using Gauss siedel
n = 1 %n y loop declaration
while n > 0.00001
v2e = (((p2-(q2)*i)/conj(v2))+y12*v1)/y12;
e2 = abs(v2e-v2);
v2 = v2e;
em = [e2];
n = max(em);
end
% s1 calculation
s1 = v1*(v1*(G1+y12)-(y12*v2)); % slack bus apparaent power
P1 = real(s1);
Q1 = imag(s1);
% Determine line flow and line losses
I12 = y12*(v1-v2);
I21 = -I12;
% Line flow
s12 = v1*conj(I12);
s21 = v2*conj(I21);
% Line losses
slose_12 = s12 + s21;
%***********************************************************************%
% Displar results
% **********************************************************************%
disp(' yi1 yi2')
disp(y)
disp('V2 value=')
disp(v2)
disp('s1 value=')
disp(s1)
disp('slose_12 value=')
disp(slose_12)
Walter Roberson on 2 May 2022
defaultans is a cell row vector. defaultans' is its transpose, and so is a cell column vector. size(defaultans') would be a vector with the number of entries in defaultans as its first value, and 1 (only one column for the transpose) as the second value. ones() of that would be an array that is all ones and has as many ones in a column as there were entries in defaultans .
Likewise the second part is similar but the *50 multiplies it by 50.
Those are together in [] so what you get is an array that has as many rows as there are entries in defaultans, and the first column is all 1 and the second column is all 50.
When that array is passed in to inputdlg() in the position it is in, it gives information about the dimensions of each input area. The leading 1 means "reserve one line of text for each input area" and the trailing 50 means "reserve 50 characters for each input area".
Why 50? Well, that appears to be an arbitrary design decision. It looked good to whoever wrote the code.

### Categories

Find more on Historical Contests in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by