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
0 个评论
回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!