adding integers in notepad

조회 수: 3 (최근 30일)
Max
Max 2011년 10월 22일
i have a notepad data.dat ..there are many integers in it seperated by commas, I have to sum the elements ..
is this an efficient way
Z=csvread('data.dat')
a=sum(Z)

답변 (1개)

Walter Roberson
Walter Roberson 2011년 10월 22일
Better would be sum(Z(:))
But if you want efficiency then you should skip the csvread layer, which would (for your purposes) just call the dlmread layer, which in turn would use testscan:
fid = fopen('data.dat','rt');
R = textscan('%f', 'Delimiter', ',');
fclose(fid);
a = sum(sum(cell2mat(R)));

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by