Trouble with if statement
Show older comments
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
Accepted Answer
More Answers (0)
Categories
Find more on Startup and Shutdown 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!