Borrar filtros
Borrar filtros

Need to Produce a different size matrix on each iteration

1 visualización (últimos 30 días)
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

Respuesta aceptada

Alan Stevens
Alan Stevens el 28 de Jun. de 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)
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 comentarios
Alan Stevens
Alan Stevens el 28 de Jun. de 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
DARLINGTON ETAJE
DARLINGTON ETAJE el 28 de Jun. de 2021
this response is correct. Thank you so much.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by