フィルターのクリア

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