Trouble with if statement
显示 更早的评论
I am trying to write a statement that if r>n2 then i require an error message to be displayed otherwise i need it to continue on and carry out the rest of the algorithm. For examples which r<n2 the code works but for r>n2 the message is displayed but an error messages stating rep not assigned is also appearing. not sure what im doing wrong. any help appreciated. here is my code:
function [rep]=assign(B)
[r,c]=size(B) % dimension of matrix. r will be number of students
W = B(:); % produces matrix in one long vector
n=length(W); %total number of elements in matrix
Projects2 = unique(W); % identifies which projects were chosen
n2=length (Projects2) % number of projects chosen
if r<n2,
[a,b]=hist(W,unique(W)); %
z2=[a',b]; % prodcuces a vector showing projects preferenced in second column and the number of times they have been preferenced in first column
rep=sortrows(z2,1); %sorts matrix by number of repetitions
else
disp(['Error: The number of students exceeds number of projects'])
return
end
end
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!