Creating a matrix row by row with for loop how?
显示 更早的评论
So I'm trying to figure out a way to create a matrix of x by y. Say x =[1 2 3 ] and y = [5 6 7 9 10 11]. I'm trying to get my script to shift the longest array y,to the right according to the length of x. So my matrix would look like this:
Newy =[5 6 7 8 9 10 11 0 0;
0 5 6 7 8 9 10 11 0;
0 0 5 6 7 8 9 10 11].
I know how to iterate the y array in respect to the length of x by doing :
y(mod((1:end)-i-1,end)+1)
I just can't figure out how to create a matrix row by row, I tried:
y1=[y zeros(1,length(x)-1)];
For i= 0:length(x)-1
y1(i,:) =y(mod((1:end)-i-1,end)+1);
But I keep generating errors . Any help would be much appreciated!
1 个评论
Azzi Abdelmalek
2013-2-15
编辑:Azzi Abdelmalek
2013-2-15
y = [5 6 7 9 10 11].
Why |[5 6 7 8 9 10 11 0 0; ?
采纳的回答
更多回答(1 个)
jessy
2013-2-15
0 个投票
1 个评论
Image Analyst
2013-2-15
If you're question is answered, please mark it as "Answered"
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!