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!