How do i Extract certain values from a list using a for loop and if statements

I have a list of student numbers and a list of absences...when student has 1 or 2 absences, trying to extract that student number and show their number of absences. please help me
StudentNumber = xlsread('ClassList.xlsx','Feb_21_2010','A4:A34');
Absences = xlsread('ClassList.xlsx','Feb_21_2010','B4:B34');
StudNum=size(StudentNumber);
fprintf('Class List as of February 21, 2010\n\n')
fprintf('Student# \t Absences\n')
for n = 1:1:StudNum
fprintf('\n%5i \t\t\t %i\n',StudentNumber(n),Absences(n))
end
disp('')
fprintf('Students with 1 or 2 Absences who will recieve a Warning Letter\n\n')
Abs=[Absences];
nAbs=length(Abs);
NumAbs(1:StudNum,1:nAbs)= false;
fprintf('Student# \t Absences\n')
for n = 1:1:nAbs
fprintf('\n%5i \t\t\t %i\n',StudentNumber(n),Absences(n))

1 件のコメント

Joseph
Joseph 2014 年 3 月 13 日
The first part works, showing all students and corresponding number of absences for each student...how can i extract just the students with 1 or 2 absences?

サインインしてコメントする。

 採用された回答

nl2605
nl2605 2014 年 3 月 13 日
for n = 1 : nAbs
if Absences(n) == 1 || Absences(n) == 2
fprintf('\n%5i \t\t\t %i\n',StudentNumber(n),Absences(n))
end
end

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

質問済み:

2014 年 3 月 13 日

コメント済み:

2014 年 3 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by