How to split data into two matrices
이전 댓글 표시
I am doing some analysis for my Honor's Thesis and am having some problems pre-processing of the data. The data is in a 4x147000 matrix. Row one is the time, two and three are my signals of interest, and the fourth is the stimulus - the condition I want to split the data up by. Due to imperfect data, not all of the events are the same length, so I need to take chunks of data either 490 or 990 columns long depending on the value of the fourth row. For example, I want to take the first 490 columns whose fourth row equals 0 and put into a new matrix "datanostim." Then I want to scan the matrix until the fourth row changes to 255, and take the first 990 columns whose fourth row equals 255 and add to a new matrix "datastim." This then repeats, so the next 490 columns whose fourth row is 0 is added to the datanostim matrix, the next 990 columns whose fourth row is 255 added to the datastim matrix, and so on.
Here is my attempt, but I would love to see other methods as well, as mine gives me the following: "Error: Function definitions are not permitted in this context."
function [datastim, datanostim] = datacutoff(data, stim, nostim)
%UNTITLED Summary of this function goes here
% data = data as matrix, fourth row as stim 0 or 255
% stim = length of stimulus
% nostim = length without stimulus
datastim = [];
datanostim = [];
i = 1;
if data(4,i) ~= data(4,i+1)
i = i+1;
else if data(4,i:i+nostim) == 0
horzcat (data(:,i:i+nostim), datanostim);
i = i+nostim;
end
end
if data(4,i) ~= data (4,i+1)
i = i+1;
else if data(4,i:i+stim) == 255
horzcat (data(:,i:i+stim), datastim);
i = i+stim;
end
end
end
Thanks!
채택된 답변
추가 답변 (1개)
카테고리
도움말 센터 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!