Need to Produce a different size matrix on each iteration
1 view (last 30 days)
Show older comments
DARLINGTON ETAJE
on 28 Jun 2021
Commented: DARLINGTON ETAJE
on 28 Jun 2021
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
0 Comments
Accepted Answer
Alan Stevens
on 28 Jun 2021
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)
3 Comments
Alan Stevens
on 28 Jun 2021
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
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!