필터 지우기
필터 지우기

Splitapply on a matrix of 1X1000

조회 수: 1 (최근 30일)
JFz
JFz 2018년 3월 5일
댓글: JFz 2018년 3월 5일
I have a matrix of 1x1000 numbers and my G is 1. When I do the splitapply on it: res = splitapply(@sum, mat, G);
The res Is the sum of the 1000 numbers. What I want is just the one row returned, i.e., res = mat;
How to get that? This is a special case. In general, there are many rows.
Thanks.

채택된 답변

Rik
Rik 2018년 3월 5일
res = splitapply(@(x) sum(x,1), mat, G);
This is about 10 times slower for mat=rand(1,1000), but it forces the direction of summation. You could also include a conditional statement:
if size(mat,1)==1
res=mat;
else
res = splitapply(@sum, mat, G);
end
  댓글 수: 1
JFz
JFz 2018년 3월 5일
Thanks! I will use the if statement.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Language Fundamentals에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by