Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7976113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:50:11+00:00 2026-06-04T08:50:11+00:00

I have a question. Suppose I have matrix A = 1 2 3 4

  • 0

I have a question.
Suppose I have matrix
A =

 1     2     3
 4     5     6
 7     8     9
10    11    12

I need to select n rolling rows from A and transpose elements in new matrix C in rows.
The loop that I use is:

n = 3;     %for instance every 3 rows of A

B = []; 

for i = 1:n 

    Btemp = transpose(A(i:i+size(A,1)-n,:)); 

    B = [B;Btemp]; 

end

C=B';

and that produces matrix C which is:

C =

 1     2     3     4     5     6     7     8     9
 4     5     6     7     8     9    10    11    12

This is what i want too do, but can I do the same job without the loop?

It takes 4 minutes to calculate for an A matrix of 3280×35 size.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T08:50:13+00:00Added an answer on June 4, 2026 at 8:50 am

    I think you can make it work very fast if you make initialization. And one other trick is to take the transpose first, since MATLAB uses columns as first index instead of rows.

    tic
    A =  reshape(1:3280*35,[3280 35])'; %# Generate an example A
    [nRows, nCols] = size(A);
    
    n = 3; %for instance every 3 rows of A
    B = zeros(nRows-n+1,nCols*n);
    At = A';
    for i = 1:size(B,1)
        B(i,:) = reshape(At(:,i:i+n-1), [1 nCols*n]); 
    end
    toc
    

    The elapsed time is

    Elapsed time is 0.004059 seconds.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about Quantifiers. Suppose that I have an array and I
I have this question: suppose that the size of char is one byte and
I have question that comes from a algorithms book I'm reading and I am
My question is suppose i have to views(Screen). when i open my application from
I have a question... Suppose that I have a table that holds names of
I am new to CSharp.I have seen this() in some code.My question is Suppose
i have a question that suppose i have 1 png which background is transparent
Question: Suppose you have a random number generator randn() that returns a uniformly distributed
So here is the question: Suppose you have 100 thousand integers which ranges from
I have question about normalization. Suppose I have an applications dealing with songs. First

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.