Forming a large matrix out of 2 separate column matrix.
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
dpb
2014-3-27
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!