I cannot get my string to print

조회 수: 2 (최근 30일)
Jacqueline Raab
Jacqueline Raab 2018년 7월 23일
댓글: Jacqueline Raab 2018년 7월 24일
The problem asks to Printing out the means of each column from an excel data sheet. I have gotten the means to print the way I want but were to assign them to the name of the column from "strColumns"
This is my script so far
dataN = csvread('DataClass.csv');
strColumns = {'LabQuiz'; 'zyBooks'; ...
'Labs'; 'Homeworks'; ...
'MidtermI'; 'MidtermII'; 'Final'; ...
'ExamAverage';'Grade'};
% Line styles
strLineStyles = {'--b', ':b', '-k', '--k', ':g', '--g', '.g', '-g', '-r'};
for colData=dataN(:,(1:9)) %index variable
m=mean(colData);
fprintf('The average of %s is %0.2f\n', strColumns{1:9},m)
end
I've tried a million different ways and I can't make it work. It should print like
The average of LabQuiz is 82.44
The average of zyBooks is 135.62
The average of Labs is 93.10
The average of Homeworks is 91.19
The average of MidtermI is 80.01
The average of MidtermII is 75.19
The average of Final is 65.56
The average of Exam Average is 73.59
The average of Grade is 86.64

채택된 답변

Walter Roberson
Walter Roberson 2018년 7월 24일
dataN = csvread('DataClass.csv');
strColumns = {'LabQuiz'; 'zyBooks'; ...
'Labs'; 'Homeworks'; ...
'MidtermI'; 'MidtermII'; 'Final'; ...
'ExamAverage';'Grade'};
% Line styles
strLineStyles = {'--b', ':b', '-k', '--k', ':g', '--g', '.g', '-g', '-r'};
for colidx = 1 : 9
colData = dataN(:,colidx) %index variable
m = mean(colData);
fprintf('The average of %s is %0.2f\n', strColumns{colidx}, m)
end
  댓글 수: 1
Jacqueline Raab
Jacqueline Raab 2018년 7월 24일
Thank you!!! I've spent HOURS trying to figure this out

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by