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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:55:32+00:00 2026-05-28T22:55:32+00:00

I am trying to create a matrix to look like this: [1 x x^2

  • 0

I am trying to create a matrix to look like this:

[1 x x^2 x^3 x^4 x^5]
[1 y y^2 y^3 y^4 y^5]
[1 z z^2 z^3 z^4 z^5]

and so on. The matrix which is going to have my base vales of x,y,z,k etc is Orig:

Orig = [ x y z k];

and my starting matrix is going to be

A = [1 x x^2 x^3 x^4 x^5];

My next line of code is

for i=(2:10)
    A(i)=A(i)^A(:,i)
end

This for loop correctly changes the power that each row needs to be raised too, however it will not go to the next value in my Orig matrix.

So basically, I need to tell Matlab a way, within the for loop, to stop using Orig(1,1) and go to Orig(1,2) for row 2.

  • 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-28T22:55:33+00:00Added an answer on May 28, 2026 at 10:55 pm

    You can do this with a double loop

    Orig = [x y z k];
    exponent = [0 1 2 3 4 5];
    
    %# preassign output to speed up loop
    output = zeros(length(Orig),length(exponent));
    
    %# loop over all elements in Orig
    for r = 1:length(Orig)
    %# loop over all exponents
    for c = 1:length(exponent)
    output(r,c) = Orig(r)^exponent(c);
    end
    end
    

    However, this is not the way you’d normally program this in Matlab.

    Instead, you’d replicate both Orig and exponent, and do the calculation in one, vectorized operation:

    %# transpose orig so that it is a n-by-1 array
    repOrig = repmat(Orig',1,length(exponent); %'#
    repExp  = repmat(exponent,length(Orig),1);
    %# perform the exponent operation in one go
    output = repOrig .^ repExp; %# note the ".", it applies operations element-wise
    

    Since a few years, there has been a shortcut version for this, using the function bsxfun. This will automatically perform the expansion we did above with repmat, and it will be faster.

    output = bsxfun(@power, Orig', exponent);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a matrix data structure in C. I have a struct
So I'm trying to create a matrix-like program with raining green code. Everything has
I am trying to create a Matrix class using c++. So far, I have
I am trying to make a loop which will create a matrix of appropriate
this is the code i am trying to create the 2d matrix m=4 tagProb=[[]]*(m+1)
I am trying to create a matrix that is 3 x n, with each
I am trying to create the below matrix in my vb.net so during processing
I am trying to create a sortable image matrix, 5x5 using scriptaculous javascript library
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
I'm trying to create a matrix of 0 values, with 1 values filling a

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.