MATLAB Answers

How do i calculate the sum of each row

조회 수: 1(최근 30일)
Lou 2021년 7월 31일
답변: dpb 2021년 7월 31일
fid = fopen('studentmarks.txt', 'r')
if fid == -1
disp('Error, check file name')
T = textscan(fid,'%s %s %f %f %f %f %f %f %f %f')

채택된 답변

dpb 2021년 7월 31일
I'd suggest to use readtable instead, first...
T = readtable('studentmarks.txt');
presuming the above format string is correct for the file content.
Without a header line in the file, the default variable names will be Var1 through VarN, you can make use of meaningful names by assigning them in T.Properties.VariableNames.
See the doc on the table class for all the syntax...
The Q? answer specifically is to use sum() with the second optional input argument to tell it to sum rows instead of columns.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by