adjust for matrix input

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일

0 개 추천

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

Lukas
Lukas 2013년 6월 5일
No it doesnt work, it doesnt calculate what i want then, thank you anyways
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.

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

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2013년 6월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by