lundi 4 avril 2016

How to index through logical vectors properly in MATLAB?

I have this piece of code

% Create judgment error column/condition = 19-16
% Create a for loop which selects all rows/condition
% Create an if statement which creates 'correction_b' = if je<-1280, +2560; if je>1280, -2560; if je>=-1280 or <=1280, je stays the same
% Attach 'correction_b' vector to main baseline/operant matrix ??

1 all_baseline_data(:,24)=(all_baseline_data(:,19)-all_baseline_data(:,16));
2 for i_b=1:numel(all_baseline_data,1)
3 if all_baseline_data(i_b,24)<-1280
4       correction_b(i_b,25)=all_baseline_data(i_b,24)+2560;
5  else if all_baseline_data(i_b,24)>1280
6         correction_b(i_b,25)=all_baseline_data(i_b,24)-2560;
7    else if all_baseline_data(i_b,24)>=-1280 & all_baseline_data(i_b,24)<=1280
8                correction_b(i_b,25)=all_baseline_data(i_b,24);
9            end
10        end
11    end
12 end

  1. when I run it, it computes the subtraction and creates a new vector (line 1) but it doesn't perform the if statement
  2. I'm also struggling to attach the newly-created 'correction_b' vector to the main all_baseline_data array -->

    all_baseline_data(i_b,24)=judgment_error_b; all_baseline_data(:,25) = judgment_error_b(correction_b);

I have a hunch the problem is in the logical vs scalar dimensions, but I'm unsure. I might also be indexing wrongly.

Aucun commentaire:

Enregistrer un commentaire