Info

This question is closed. Reopen it to edit or answer.

Vectors from for loop in same column

1 view (last 30 days)
MadjeKoe
MadjeKoe on 26 Oct 2020
Closed: MATLAB Answer Bot on 20 Aug 2021
Hi all! I've made the following for loop, where 4 outcomes go into a new matrix in 4 different columns (for target 1, 2, 3 & 4). Now I want these outcomes all added as 1 extra column in matrix 'res', in the right order so that each outcome is paired with the correct trial number. Can somebody please help me with this??
res = S.res;
trials = res(:,1);
targets = res(:,7);
responses = res(:,8);
oria = [3,4,5,6];
tar = [1,2,3,4];
num = numel(oria);
out = cell(1,num);
for k = 1:num
tarsel = targets==tar(k);
resp = responses(tarsel);
orib = res(tarsel,oria(k));
err = resp - orib;
err(err<-90) = err(err<-90)+180;
err(err>90) = err(err>90)-180;
out{k} = err;
end
out = [out{:}];

Answers (1)

Rohit Pappu
Rohit Pappu on 29 Oct 2020
Edited: Rohit Pappu on 30 Oct 2020
As per my understanding of the question, this is a possible solution
res = S.res;
trials = res(:,1);
targets = res(:,7);
responses = res(:,8);
oria = [3,4,5,6];
tar = [1,2,3,4];
num = numel(oria);
out = cell(1,num);
%% Find the number of rows in res
resSize = size(res);
rows = resSize(1);
%% Define a vector containing zeros to map out with corresponding trials
vout = zeros(1,cols);
for k = 1:num
tarsel = targets==tar(k);
resp = responses(tarsel);
orib = res(tarsel,oria(k));
err = resp - orib;
err(err<-90) = err(err<-90)+180;
err(err>90) = err(err>90)-180;
out{k} = err;
%% store all outputs in corresponding positions
vout(tarse1) = err;
end
out = [out{:}];
%% Concatenate vout to the last column of res
res = [res, vout]

Tags

Community Treasure Hunt

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

Start Hunting!