Forming a large matrix out of 2 separate column matrix.

1 view (last 30 days)
Im having trouble trying to create a matrix that creates a graph like the one attached. I have managed to get half way but cant figure out how to create the final matrix. I want to get it so the first column repeats after a certain number of times. The second column would be 100 equally spaced numbers ranging from 0 to 100. Ive also attached my script to help.

Accepted Answer

dpb
dpb on 27 Mar 2014
I presumed you could see how to get from the simpler "Matlab way" of computing the power series to the scaled version, sorry...
refine = 1.02; % Refinement Parameter
L=100; % length desired
x=refine.^(0:L-1).'; % the power series
x = cumsum(x)/sum(x); % Cumulative Sum scaled
Try
all(x)==all(cumsum(dx_scaled))
to prove it works numerically or write the algebra from your loops to see it analytically.
Now to see if I can finally understand what you're after for the other column...I seem to be dense here. :( ... Oh, ok, I see--not sure why it took so long; perhaps because I was too focused on the code and the other numbers instead of the above verbiage that is clear. OK, try the following --
You've got the base case; since it's a tiling you want repmat is your friend.
N=1000; % The total length desired
n=fix(N/L); % Number of tilings of L to hit N w/o going over if not even
y=linspace(0,1,100).';
grid=repmat([x y],n,1);
doc repmat
for more detail on the last step. Work thru the examples in Getting Started on array operations and the colon and so on to get a feel for how Matlab vectorized operations work to eliminate the explicit loops.
  2 Comments
dpb
dpb on 27 Mar 2014
OK, good...I cleaned up the divergent portions of the thread for posterity.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!