resize Excel data matrix

5 visualizaciones (últimos 30 días)
EK
EK el 7 de Jun. de 2023
Comentada: EK el 7 de Jun. de 2023
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?

Respuesta aceptada

Simon Chan
Simon Chan el 7 de Jun. de 2023
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 comentario
EK
EK el 7 de Jun. de 2023
Thank you very much!

Iniciar sesión para comentar.

Más respuestas (1)

Divyam
Divyam el 7 de Jun. de 2023
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.

Categorías

Más información sobre Data Type Identification en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by