I am trying to put zero on top of each generated column.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Masoud Taleb
el 23 de Abr. de 2020
Comentada: BobH
el 24 de Abr. de 2020
Hello,
I am trying to put zero on top of each generated column. Assuming that "A", "ds" and "ws" differ in each of my data files, I need your help to make c2 generic for every file with known "ws", "ds" and "A". In below sample, data are not that much; I do not know how to expand it for big files.
I hope someone can help in this :)
Thanks
ws = 6 %row
ds = 4 %column
A = [1;3;5;5;6;7;8;5;1;6;9;2;6;7;4;5;6;7;8;5;5;3;2;1]
for i = 1:ds
c2 = [0;A(1:ws*1);0;A(ws+1:ws*2);0;A(ws*2+1:ws*3);0;A(ws*3+1:end)]
end
g= reshape (A,ws,ds)
g2 = reshape (c2 , ws+1, ds)
0 comentarios
Respuesta aceptada
BobH
el 23 de Abr. de 2020
Your first reshape is the right approach, to arrange the values into a matrix with the right number of columns
ws = 6; %row
ds = 4; %column
A = [1;3;5;5;6;7;8;5;1;6;9;2;6;7;4;5;6;7;8;5;5;3;2;1];
g= reshape (A,ws,ds)
g =
1 8 6 8
3 5 7 5
5 1 4 5
5 6 5 3
6 9 6 2
7 2 7 1
Flip the columns, append a row of 0 at the new bottom, flip again
fg = flipud(g);
fg(end+1,:) = 0;
g0 = flipud(fg)
g0 =
0 0 0 0
1 8 6 8
3 5 7 5
5 1 4 5
5 6 5 3
6 9 6 2
7 2 7 1
2 comentarios
BobH
el 24 de Abr. de 2020
David's answer is far superior, and he rightly mentions that a proper reshape depends on your original array being neatly divisible by the number of columns or rows.
Please use his answer.
Más respuestas (1)
David Hill
el 23 de Abr. de 2020
Assuming you know that mod(length(A),ws)==0
g=reshape(A,ws,[]);
g2=[zeros(1,size(g,2));g];
Ver también
Categorías
Más información sobre Characters and Strings 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!