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
EK
EK 2023년 6월 7일
Thank you very much!

댓글을 달려면 로그인하십시오.

추가 답변 (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