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: How can I map two columns from table A and B if
Short version: Can we read from dozens or hundreds of table partitions in a
Short version: can you help me fill in this code? var conkeror_settings_dir = ".conkeror.mozdev.org/settings";
Short version: How can I get a regex that matches a@a.aaaa but not a@a.aaaaa
short version: how can I get rid of the multiple-versions-of-python nightmare ? long version:
Short version: How can I receive input messages in Windows with C++/C when the
Short version (if you can answer the short version it does the job for
Short version: After branching in P4, how can I find out the source changelist
Short version: I want to trigger the Form_Load() event without making the form visible.
Short version: I'm wondering if it's possible, and how best, to utilise CPU specific

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.