adding integers in notepad
2 views (last 30 days)
Show older comments
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)
0 Comments
Answers (1)
Walter Roberson
on 22 Oct 2011
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)));
0 Comments
See Also
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!