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 3439898
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:22:01+00:00 2026-05-18T08:22:01+00:00

Short Version How can I do concatMap in MATLAB? I’m trying to build a

  • 0

Short Version

How can I do concatMap in MATLAB? I’m trying to build a single vector from a series of smaller, differently sized vectors. I know I can do:

result = [];
for i=1:N
    result = [result nextPart(i)];
end

but that has a serious speed impact and there must be a smarter way to do concatMap.


Long Version

I’m trying to write a MATLAB function that returns the counterdiagonals of a block. For example, if you have the block:

1 2 4
3 5 7
6 8 9

then counterDiagonals(block) should return [1 2 3 4 5 6 7 8 9].

I have a function that will find a single counter diagonal of a block. i.e. counterDiagonal(x, 3) will return [4 5 6].

Therefore, counterDiagonals should be as simple as concatMap counterDiagonal(x, i) (1:N) where N is (2*length(block)-1). How can I do this in MATLAB in an efficient way?

  • 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-18T08:22:01+00:00Added an answer on May 18, 2026 at 8:22 am

    I believe what you want to do can be accomplished using the functions ROT90 and SPDIAGS:

    A = [1 2 4; 3 5 7; 6 8 9];  %# Sample matrix
    result = rot90(A);          %# Rotate the matrix counter-clockwise
    result = spdiags(result);   %# Find all the diagonals
    result = result(result ~= 0).';  %'# Remove zero padding and format the results
                                      %#   into a row vector
    

    And you should end up with result = [1 2 3 4 5 6 7 8 9].

    EDIT: As Amro mentions in a comment, the above code assumes that there are no zeroes in the original matrix A. If there are zeroes in the original matrix, one solution is to replace them with a non-zero flag value that you know doesn’t appear in the original matrix (like, for example, NaN), run the above code, then replace the flag values in the result:

    A = [0 2 4; 3 0 7; 6 8 0];  %# Sample matrix
    result = rot90(A);          %# Rotate the matrix counter-clockwise
    result(result == 0) = nan;  %# Replace zeroes with NaN
    result = spdiags(result);   %# Find all the diagonals
    result = result(result ~= 0).';  %'# Remove zero padding and format the results
                                      %#   into a row vector
    result(isnan(result)) = 0;  %# Put the original zeroes back
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Short version: Can we read from dozens or hundreds of table partitions in a
In every Visual Studio.NET version you can set keyboard shortcuts using menu Tools ->
I'm trying to create a short bash script someone could run in cygwin to
How can I download page on this link http://www.kayak.com/s/search/air?ai=kayaksample&do=y&ft=ow&ns=n&cb=e&pa=1&l1=ZAG&t1=a&df=dmy&d1=4/10/2010&depart_flex=exact&r1=y&l2=LON&t2=a&d2=11/10/2010&return_flex&r2=y Link changes to short version
Ok a short question: Is there any SIMPLE software with a GUI, that lets
Short story I've got a PHP script filtering incoming mail using a .qmail file.
In short: how to put a zipful of csv data into mysql? Long: I
I need to change the old Win98 short path names to long path names.
Similar questions have been asked before but after a day of going through the
Similar to Does TDD mean not thinking about class design? , I am having

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.