Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· OpenAIAi2 WildChat-4.8M (AI2)

A has 2928 row and 1 column, I want to separate every 24 row from column 1 and put it in…

  1. User

    A has 2928 row and 1 column, I want to separate every 24 row from column 1 and put it in matrix B column 1 and two continuously to the end. write code for matlab.

  2. Assistant

    Assuming the 2928 rows are stored in a column vector A, you can use the reshape function to create a 24-by-122 matrix B and then transpose it to get a 122-by-24 matrix. Then you can reshape B into a 2928-by-2 matrix C by concatenating the first and second columns.

    Here's the code:

    A = rand(2928,1); % example data B = reshape(A, [24,122]).'; % reshape to 122x24 and transpose C = reshape(B, [2928,2]); % concatenate columns

    Note that the reshape function fills in elements of the original vector in column-major order, so the second argument [24,122] specifies the desired size in row-major order, which is why we need to transpose the result.