Borrar filtros
Borrar filtros

Why am I getting an unbalanced parenthesis error?

1 visualización (últimos 30 días)
Andrew Poissant
Andrew Poissant el 16 de Feb. de 2017
Respondida: Star Strider el 16 de Feb. de 2017
I am getting an error in line 8 of my code "if (~strcmp(a[:], ' '))" saying "Unbalanced or unexpected parenthesis or bracket." Why do I keep getting this error?
function [states, b] = Estimate_TransitionProbabilities(a)
n = length(a);
s = [];
b = [];
j = 0;
for i = 1:n
if (~strcmp(a[:], ' '))
s = (a, char(a(i)));
elseif (-isempty(s))
i = j+1;
b(j) = s;
s = [];
end
if (i == n && -isempty(s))
j = j+1;
b(j) = s;
end
end
states(l) = b(l); l = 1;
for i = 2:length(l)
num = 0
for j = 1:i-1
if (~strcmp(b(i),b(j)))
num = num+1;
end
if (num == i-1)
l = l+1;
state(l) = b(i)
end
end
end
num = zero(length(states), length(states))
for i = 1:length(states)
for j = 1:length(states)
for k = 1:length(i)
if (strcmp(b(k), states(i)) & strcmp(b(k+1), states(i)))
num(i,j) = num(i,j)+1
end
end
end
end
end

Respuestas (1)

Star Strider
Star Strider el 16 de Feb. de 2017
MATLAB uses parentheses ‘()’ not square brackets ‘[]’ for its subscript designations.
Try this:
if (~strcmp(a(:), ' '))
If ‘a’ is a cell array, this would be more appropriate:
if (~strcmp(a{:}, ' '))
Note the curly brackets ‘{}’ for cell referencing.
It would help to know what ‘a’ is.

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by