How to Convert 2D matrix to 3D with time as 3rd dimension
Mostrar comentarios más antiguos
I have a code which results in a 2D matrix .The code is in a loop . So I get many 2D matrix values. I want to convert it into a 3D matrix with 3rd Dimension as time. How can I do this ?
Respuestas (2)
Azzi Abdelmalek
el 13 de Jun. de 2013
A(:,:,k)=B
7 comentarios
Venkata Jayadeep Kodali
el 13 de Jun. de 2013
Azzi Abdelmalek
el 13 de Jun. de 2013
Editada: Azzi Abdelmalek
el 13 de Jun. de 2013
You can not, K should be a positive integer
Venkata Jayadeep Kodali
el 13 de Jun. de 2013
James Tursa
el 13 de Jun. de 2013
Editada: James Tursa
el 13 de Jun. de 2013
Add a line:
the_time(k) = whatever format of time you want to store
Reminder that best practice would be to pre-allocate A and the_time.
Venkata Jayadeep Kodali
el 13 de Jun. de 2013
Evan
el 13 de Jun. de 2013
Do you mean you want B to be the time? If so, yes, tic/toc would work. You would call tic outside the loop then have something like this inside:
A(:,:,k) = toc;
Azzi Abdelmalek
el 13 de Jun. de 2013
You can also use a struct format
for k=1:5
A=rand(4); % for example
data(k).time=k % for example
data(k).matrix=A
end
Youssef Khmou
el 13 de Jun. de 2013
hi,
You can the method provided above, but the function "toc" may have problems , i propose using an integer variable , here is an example :
% Eeach time we get a 2D AWGN matrix with different Standard Deviation
N=100;
L=200;
for n=1:N
r=rand;
M(:,:,n)=r*randn(L);
end
If your loop indexes start differently( negative values per example , try this solution :
N=100;
L=200;
time=1;
for n=-10:N
r=rand;
M(:,:,time)=r*randn(L);
time=time+1;
end
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!