resize Excel data matrix
3 次查看(过去 30 天)
显示 更早的评论
Hi,
I am trying to resize Excel data matrix and would like to ask if there are easy way to do it in matlab
I have matrices with logfile and data. The first 5 columns is the log fille that logs stimuli representation in time (an example, attached below ). The rows are time and the columns are events. The first column logs stimuli id in time. (No stimulus =0, stimulus : 1 2 3 4 5 or 6) The second column logs the trial stages(1=pre stimulus, 2=stimulus, 3=poststimulus interval); However the pre and post stimulus intervals are not exactly the same for all stimuli.
I need to take given number of raws before and after the each stimulus (for example 50 rows before stimulus, Stimulus, and 50 rows after the stimulus) and reconcatinate the matrix in the same order it was before. Could anyone help with this?
0 个评论
采纳的回答
Simon Chan
2023-6-7
Try this to see whether it is what you want.
rawdata = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1404904/data%20_matrix.xlsx');
idx = diff(rawdata(:,1)~=0);
xstart = find(idx==1)+1;
xend = find(idx==-1);
Nrow = 50;
output = arrayfun(@(r) rawdata((xstart(r)-Nrow):(xend(r)+Nrow),:),1:numel(xstart),'uni',0);
combine = cell2mat(output');
更多回答(1 个)
Divyam
2023-6-7
You can follow these steps:
- Create a matrix, A which has the same number of rows as your logfile matrix and the number of columns which you require (say 50). You can create it using the command given below.
A = zeros(rows, 50)
- Then you can concatenate this matrix to the start and end of your logfile matrix. The command for the same which generates a new concatenated matrix B is given below.
B = [A logfile A]
The matrix B successfully has the contents arranged in the order you require.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Export to MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!