Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Vectors from for loop in same column

1 vue (au cours des 30 derniers jours)
MadjeKoe
MadjeKoe le 26 Oct 2020
Clôturé : MATLAB Answer Bot le 20 Août 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{:}];

Réponses (1)

Rohit Pappu
Rohit Pappu le 29 Oct 2020
Modifié(e) : Rohit Pappu le 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]

Cette question est clôturée.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by