フィルターのクリア

Why am I getting an unbalanced parenthesis error?

2 ビュー (過去 30 日間)
Andrew Poissant
Andrew Poissant 2017 年 2 月 16 日
回答済み: Star Strider 2017 年 2 月 16 日
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 Center および File ExchangeStartup and Shutdown についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by