What is wrong with my script?

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 Comments

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.
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')

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 8 Jun 2018
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).

Categories

Find more on Historical Contests in Help Center and File Exchange

Asked:

on 8 Jun 2018

Commented:

Jan
on 9 Jun 2018

Community Treasure Hunt

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

Start Hunting!