Effacer les filtres
Effacer les filtres

Why am I getting an unbalanced parenthesis error?

1 vue (au cours des 30 derniers jours)
Andrew Poissant
Andrew Poissant le 16 Fév 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

Réponses (1)

Star Strider
Star Strider le 16 Fév 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.

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by