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

  • Home
  • SEARCH
  • 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 6775401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:54:10+00:00 2026-05-26T15:54:10+00:00

Assuming vector v of size 1 x n and function fun that takes in

  • 0

Assuming vector v of size 1 x n and function fun that takes in a vector of length L and returns a vector of size p x 1.

Is there a MATLAB function that would take in vector v, process each sliding window of length L with function fun, and return a matrix of size p x n (or p x (n-L)).

I am aware this could be achieved with creating a matrix of windowed vectors with im2col and processing each of those, but this takes too much memory for a long vector v.

  • 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-05-26T15:54:10+00:00Added an answer on May 26, 2026 at 3:54 pm
    funsl=@(is) fun(v(is:is+l-1));
    cell2mat(arrayfun(funsl,1:length(v)-l+1,'UniformOutput',false))
    

    What I did here is define an anonymous function that, for a fixed v and l and a starting index parameter (is), gets the respective slice of v and applies fun to it.

    Then this function is applied, via arrayfun, to all useful values for this starting index. For reasons I myself cannot quite name at the moment, each application returns a p x 1 vector, but arrayfun cannot arrange it into a proper matrix, thus the UniformOutput=false setting and the cell2mat call around it.

    Edit: To test this with a function that turns 1-by-5 vectors into 4-by-1 vectors I used

    l=5;v=1:12; fun=@(x) cumsum(x(2:end))';
    

    and got this result:

    ans =
    
     2     3     4     5     6     7     8     9
     5     7     9    11    13    15    17    19
     9    12    15    18    21    24    27    30
    14    18    22    26    30    34    38    42
    

    Note again that in the definition of funsl v is fixed, To apply this approach to different v you could make another function that takes v (and l, if you do not want to fix this) as parameter(s), contains the two lines above and returns the result of the second one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assuming that: vector<string> mvec; has some elements on it Partial code: for(vector<string>::iterator it1 =
I would like to call a function on all elements of a boost::fusion::vector. The
Assuming such a query exists, I would greatly appreciate the help. I'm trying to
Assuming there are 5 items in the settings file ( MySetting1 to MySetting5 ),
Assuming network access is sporadic with no central server, what would be the best
Assuming a fluid layout is not an option (since that is a different discussion
When a vector is created it has a default allocation size (probably this is
Assuming a vector (or matrix) of ids > 1 2 3 3 2 Let's
Are there any known hash algorithms which input a vector of int's and output
Say I need a new type in my application, that consists of a std::vector<int>

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.