Need to Produce a different size matrix on each iteration

1 次查看(过去 30 天)
Good Morning,
I need your urgent help. I have a presentation on this in a few hours. I am trying to create one matrix concatenated to the previous per loop.
the concept is that the abc first matrix is [1 51]. the second matrix is [1 51;2 52]; the third matrix is [1 51;2 52;3 53]; and so on.
wqe=[1;2;3;4;5;6;7;8;9;10;11;12;13;14;15];
kli=[51;52;53;54;55;56;57;58;59;60;61;62;63;64;65];
hsd=size(kli,1);
kas=zeros(hsd,1);
sak=zeros(hsd,1);
abc=repmat({zeros(hsd,1)},hsd,1);
for i=1:hsd
kas(i)=wqe(i);
sak(i)=kli(i);
end
for h=2:1:hsd
abc{i}=[kas(i-1) sak(i-1);kas(i) sak(i)];
end

采纳的回答

Alan Stevens
Alan Stevens 2021-6-28
Try the following
wqe=[1;2;3;4;5;6;7;8;9;10;11;12;13;14;15];
kli=[51;52;53;54;55;56;57;58;59;60;61;62;63;64;65];
hsd=size(kli,1);
kas=zeros(hsd,1);
sak=zeros(hsd,1);
abc=zeros(hsd,2);
for i=1:hsd
kas(i)=wqe(i);
sak(i)=kli(i);
end
abc(1,:) = [kas(1) sak(1)];
for h=2:1:hsd
abc(h,:)=[kas(h) sak(h)];
end
disp(abc)
1 51 2 52 3 53 4 54 5 55 6 56 7 57 8 58 9 59 10 60 11 61 12 62 13 63 14 64 15 65
  3 个评论
Alan Stevens
Alan Stevens 2021-6-28
More like this?
wqe=[1;2;3;4;5;6;7;8;9;10;11;12;13;14;15];
kli=[51;52;53;54;55;56;57;58;59;60;61;62;63;64;65];
hsd=size(kli,1);
kas=zeros(hsd,1);
sak=zeros(hsd,1);
abc=zeros(hsd,2);
for i=1:hsd
kas(i)=wqe(i);
sak(i)=kli(i);
end
abc(1,:) = [kas(1) sak(1)];
for h=2:1:hsd
abc(h,:)=[kas(h) sak(h)];
end
matrix{1}=abc(1,:);
for i = 2:hsd
matrix{i}=abc(1:i,:);
end

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by