Summing across columns

조회 수: 14 (최근 30일)
discoduck
discoduck 2011년 2월 17일
I have some data containing 33 columns. I need to sum across columns 2:33 and then plot against the first column. Any ideas?

답변 (2개)

Matt Tearle
Matt Tearle 2011년 2월 17일
Just a simplification to Paulo's version -- "plot against the first column" means plot the sum as y and the first column as x:
a=rand(10,33)
b=sum(a(:,2:end),2)
plot(a(:,1),b)

Paulo Silva
Paulo Silva 2011년 2월 17일
clf %clear a figure
hold on %additive plotting
a=rand(10,33) %generate some random data
b=sum(a(:,2:end),2) %do the sum of columns of a from 2 to the last one
plot(a(:,1)) %plot the first column in blue
plot(b(:,1),'r') %plot the sum of the columns in red
title('The sum of columns for 2 to 33 is the red line')
xlabel('The first column is the blue line')

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by