fill part of vector
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
yousef Yousef
el 9 de Abr. de 2014
Comentada: dpb
el 9 de Abr. de 2014
I have a=[1 2 5 4 2 7 4 8 2 3](10 values),b=[0 1 2 3],I want to fill a so that
a=[0 1 2 3 0 0 0 0 0 0],
0 comentarios
Respuesta aceptada
dpb
el 9 de Abr. de 2014
There's nothing left so there's no point in doing anything except sotoo--
a=0; a(1:length(b))=b;
a=[b zeros(1,length(a)-length(b)];
An essentially innumerable ways to get there, choose one and go on.
3 comentarios
dpb
el 9 de Abr. de 2014
so fix the typo of I forgot that '0' is a scaler and won't fill...
a=zeros(size(a)); a(1:length(b)=b;
surely that's not too tough.
Más respuestas (1)
yousef Yousef
el 9 de Abr. de 2014
1 comentario
dpb
el 9 de Abr. de 2014
Basically the same thing--just use colon operator to address the elements of concern ensuring the LHS and RHS have same length of subscripting.
All of these kinds of operations are in the "Getting Started" section of the documentation under array addressing. I suggest working thru those early sections and the exercises/examples therein to get the basics down.
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!