resize Excel data matrix

3 次查看(过去 30 天)
EK
EK 2023-6-7
评论: EK 2023-6-7
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?

采纳的回答

Simon Chan
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
Divyam 2023-6-7
Hi @EK,
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.

类别

Help CenterFile Exchange 中查找有关 Data Export to MATLAB 的更多信息

产品


版本

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by