insert new rows and movin data into new rows

clear all; clc;
n = 1000;
lambda = 480;
WAK = poissrnd(lambda,1,n);
WK(1) = WAK(1);
for i=1:n-1
WK(i+1) = WK(i) + WAK(i+1);
end
how to make WK multi-dimensional with : 1440*(t-1) <= WK(i) < 1440*t , suppose :
  • for t=1 , WK(i) on row 1
  • for t=2 , WK(i) on row 2
  • for t=3, WK(i) on row 3
  • dst.

 Respuesta aceptada

Image Analyst
Image Analyst el 16 de Abr. de 2022

0 votos

Hint:
Use repmat() to copy the 1-D WK into additional rows or columns.
but I'm not sure what it's asking because I don't know if t is rows or columns, and every row or column has the same value, which is just WK(i).

6 comentarios

Takim Mustakim
Takim Mustakim el 16 de Abr. de 2022
Example 1-D WK = [ 1 2 3 4 5 6 7 8 9 10] I want to make WK being T-D WK like a : WK = [ 1; 2 3 4 5 6 7; 8 9 10] With (t-1)*2 <= WK < t*2
Image Analyst
Image Analyst el 16 de Abr. de 2022
Editada: Image Analyst el 16 de Abr. de 2022
WK = [ 1 2 3 4 5 6 7 8 9 10]
WK = 1×10
1 2 3 4 5 6 7 8 9 10
WK = [ 1; 2 3 4 5 6 7; 8 9 10]
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
As you can see, your desired output is not a valid matrix.
Please tell me what "t" is and give the 2-D matrix output you expect for that 1-D WK vector.
Do you mean just
WK2 = reshape(WK, [], 1440);
Takim Mustakim
Takim Mustakim el 17 de Abr. de 2022
i'm sorry
i mean is WK becomes
WK = [1 0 0 0 0 0 0 0 0 0 0; 2 3 4 5 6 7 0 0 0 0; 8 9 10 0 0 0 0 0 0 0]
Well you could just do
WK = [1 0 0 0 0 0 0 0 0 0; 2 3 4 5 6 7 0 0 0 0; 8 9 10 0 0 0 0 0 0 0]
WK = 3×10
1 0 0 0 0 0 0 0 0 0 2 3 4 5 6 7 0 0 0 0 8 9 10 0 0 0 0 0 0 0
(obviously your "correction" didn't work, so I corrected your correction) or you could do
WK1 = [ 1 2 3 4 5 6 7 8 9 10]
WK1 = 1×10
1 2 3 4 5 6 7 8 9 10
WK = zeros(3, 10);
WK(1,1) = WK1(1,1);
WK(2, 1:6) = WK1(2:7);
WK(3, 1:3) = WK1(8:10)
WK = 3×10
1 0 0 0 0 0 0 0 0 0 2 3 4 5 6 7 0 0 0 0 8 9 10 0 0 0 0 0 0 0
What's the use case? Why do you need to do this quirky thing anyway?
Takim Mustakim
Takim Mustakim el 17 de Abr. de 2022
not like what a mean but thank you for your response
It's literally the output matrix you said WK should become, element by element.
And you never answered my questions: "What's the use case? Why do you need to do this quirky thing anyway?"
That might help me figure out what is wanted.
Looking at the second half of your original question, the best I can figure out what you mean is to use
WK2 = reshape(WK, [], 1440);

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre MATLAB Coder en Centro de ayuda y File Exchange.

Productos

Versión

R2021a

Etiquetas

Preguntada:

el 16 de Abr. de 2022

Comentada:

el 17 de Abr. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by