Info

此问题已关闭。 请重新打开它进行编辑或回答。

Vectors from for loop in same column

2 次查看(过去 30 天)
MadjeKoe
MadjeKoe 2020-10-26
关闭: MATLAB Answer Bot 2021-8-20
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{:}];

回答(1 个)

Rohit Pappu
Rohit Pappu 2020-10-29
编辑:Rohit Pappu 2020-10-30
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]

此问题已关闭。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by