Why am I getting an unbalanced parenthesis error?

2 次查看(过去 30 天)
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

回答(1 个)

Star Strider
Star Strider 2017-2-16
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.

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by