I need to put "a" matrix one below the other in a single matrix. That is, I need to place in a matrix of dimension a*b x N, where the first b rows correspond to sec=1, from row b+1 to row 2b+1 the second matrix corresponding to sec=2, and so on.
For example for this code:
a=100;
b=5;
N=8;
for sec=1:a
PM=rand(b,N)
end
I want to create the matrix of dimension 500x8, formed by the 100 matrix generated, where the first 5 rows correspond to the matrix obtained for sec = 1, from row 6 to row 11 the second matrix corresponding to the matrix obtained for sec = 2, and so on.

댓글 수: 3

Bob Thompson
Bob Thompson 2019년 10월 14일
편집: Bob Thompson 2019년 10월 14일
Why do you want 6-11 to be for 2sec? There were only five rows for the first second.
Where is your data coming from? Or is it just randomly generated numbers?
Assuming that you have data, I would use something like the following:
for i = 1:100
data((i-1)*5+1:i*5,:) = rand(5,8);
end
Romina
Romina 2019년 10월 14일
My data comes from another code and not from this. In the original code something similar happens, then, for every second i get a 1000 x 1000 matrix.
There were only five rows for the first second and five rows for sec 2. It's 6-10 and not 6-11 as i said before
Bob Thompson
Bob Thompson 2019년 10월 14일
Ok, well the indexing on 'data' should be what you're looking for. I can't write the right hand side of the equation for you because I don't know what it looks like.

댓글을 달려면 로그인하십시오.

 채택된 답변

Fabio Freschi
Fabio Freschi 2019년 10월 14일

0 개 추천

You can just append the matrices as they come.
a=100;
b=5;
N=8;
% inital empty matrix
PM = [];
% your loop
for sec=1:a
PM = [PM; rand(b,N)];
end

댓글 수: 6

Of course you can also preallocate
a=100;
b=5;
N=8;
% inital zero matrix
PM = zeros(a*b,N);
% your loop
for sec=1:a
idx = (1:b)+(sec-1)*b;
PM(idx,:) = rand(b,N);
end
Romina
Romina 2019년 10월 14일
I tried to transfer this idea to my code but I can't get what I want. Thanks anyway
Fabio Freschi
Fabio Freschi 2019년 10월 14일
If you can be more precise, I would try to help
If I understand correctly the method works. After this section:
...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% I NEED SAVE IN A MATRIZ PotMem, this 10 Potenciales_Membrana matrix,
Potenciales_Membrana(t,1:N)=v
u=u+a.*(0.2*v-u);
STDP(:,t+D+1)=0.95*STDP(:,t+D);
end
put these lines
idx = (1:c)+(sec-1)*c;
PotMem(idx,:) = Potenciales_Membrana;
and in the end you should have PotMem filled with Potenciales_Membrana. Let me know if it is what you need.
Romina
Romina 2019년 10월 14일
Yes! That is exactly what I needed! Thank you very very much!
Fabio Freschi
Fabio Freschi 2019년 10월 14일
My pleasure! If my answer solve your original problem, please accept it!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

2019년 10월 14일

댓글:

2019년 10월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by