What is wrong with my script?

1 次查看(过去 30 天)
jakobjakob
jakobjakob 2018-6-8
评论: Jan 2018-6-9
Who could help me? What is wrong with my script? There is no counting...
index_aanname = find(strcmp(alldata(:,5), 'Aanname') == 1);
TA = tijdnum(index_aanname);
TA10 = TA - 10;
SA = speler(index_aanname);
bal = 0 ;
medespeler_met_bal = 0 ;
medespeler_zonder_bal = 0 ;
tegenstander = 0 ;
open_ruimte = 0 ;
overzicht_veld = 0 ;
overig = 0 ;
for k = 1:length(index_aanname)
firstTouchIndex = index_aanname(k);
firstTouchTimestamp = alldata{firstTouchIndex,1};
j = firstTouchIndex - 1;
while j >= 1 && (firstTouchTimestamp - alldata{j,1}) <= 10.0
viewingBehaviour = alldata{j,9};
j = j - 1;
if strcmp(kijkrichting(i),'Bal') == 1
bal = bal + 1
elseif strcmp(kijkrichting(i),'Medespeler met bal') == 1
medespeler_met_bal = medespeler_met_bal + 1;
elseif strcmp(kijkrichting(i),'Medespeler zonder bal') == 1
medespeler_zonder_bal = medespeler_zonder_bal + 1;
elseif strcmp(kijkrichting(i),'Tegenstander') == 1
tegenstander = tegenstander + 1;
elseif strcmp(kijkrichting(i),'Open ruimte') == 1
open_ruimte = open_ruimte + 1;
elseif strcmp(kijkrichting(i),'Overzicht veld') == 1
overzicht_veld = overzicht_veld + 1;
elseif strcmp(kijkrichting(i),'Overig') == 1
overig = overig + 1;
end
end
end
  2 个评论
Rik
Rik 2018-6-8
Have you tried the debugger? You can set breakpoints to stop the execution of your code and continue step by step. That way you can watch the point where variables take on unexpected values. The debugging capabilities are one of the main features in Matlab that are superior to programs like Octave. You should really use it.
Jan
Jan 2018-6-9
By the way: There is no reason to compare the output or strcmp with 1. strcmp replies a logical value already:
if strcmp(kijkrichting(i), 'Bal')

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2018-6-8
Since kijkrichting is being compared to strings, it's most likely a cell array. Therefore you should be using {} instead of (). See the FAQ for a good explanation of when to use bracket, braces, or parentheses: https://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F
So use kijkrichting{i} instead of kijkrichting(i).

类别

Help CenterFile Exchange 中查找有关 Data Type Identification 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by