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!