필터 지우기
필터 지우기

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