adjust for matrix input

1 次查看(过去 30 天)
Lukas
Lukas 2013-6-5
How do I in a spimple way adjust this below to be able to handle a matrix as input, for example if:
p_t2=rand(2,1000)
pt2=rand(2,40)
JJ=[];
for z=1:40
for v=1:25
XX=p_t2(v)./pt2;
JJ=[JJ sum(XX)];
end
p_t2(1:25)=[];
pt2(:,1)=[];
end
I want the output JJ be a matrix with dimension (2,1000)

回答(1 个)

Azzi Abdelmalek
Azzi Abdelmalek 2013-6-5
编辑:Azzi Abdelmalek 2013-6-5
Use sum(XX,2) instead of sum(XX)
p_t2=rand(2,1000);
pt2=rand(2,40);
JJ=[]
for z=1:40
for v=1:25
XX=p_t2(v)./pt2;
JJ=[JJ sum(XX,2)];
end
p_t2(1:25)=[];
pt2(:,1)=[];
end
  3 个评论
Azzi Abdelmalek
Azzi Abdelmalek 2013-6-5
What do you mean: it's not working
What was the result?
Jan
Jan 2013-6-5
So, Lukas, I suggest that you explain what you want to calculate. We cannot guess it.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by