Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.


Mary
Posts:
20
Registered:
12/7/10


Problems with Strings!
Posted:
Jun 25, 2013 3:16 PM


Hello!
I'm writing a code for which a user inputs a line of strings, and matlab matches those strings to data in a loaded xls spreadsheet, runs calculations and then spits out the data into a new spreadsheet.
I'm having two problems: 1.) user input  I cant seem to get this to work properly. MATLAB insists that the user is loading in a string character by character and wont take the list of inputs as a vector of strings.
(I'm hoping to allow the user to copy and paste a list of usernames from a word doc/spreadsheet, and paste them when prompted for an input)
2.) generating the spreadsheets for some reason MATLAB refuses to acknowledge my column headers when using xlswrite. I even followed a reccomended tutorial from MATLAB for how to set things up!
This is what I have so far!
function KRNS_statusReport %% User Input Prompt % Prompts the user to load the current module status .xls file fprintf('Select the current module status log. File must be in .xls format') [FileName , PathName ] = uigetfile('*.xls','Select the current module status log') modStatus = fullfile(PathName,FileName); [num, txt, raw]= xlsread(modStatus);
***PROBLEM 1. HERE*** x = strcat(input('Enter usernames for current cohort','s')); userNames = strsplit(x)
a=1; %% String Match Input Usernames with those in Module Status Spreadsheet for i= 1:numel(userNames) compare= strcmp (userNames(a),raw(:,1)) username = userNames(a) usernameLocation = find(compare, 1) moduleLocation = usernameLocation  1; completedModules = num(moduleLocation,3) completedBlocks = num(moduleLocation,2) startTime = raw(usernameLocation,5) endTime = raw(usernameLocation,6)
totalCompleted = 0; partialUnderFive = 0; partialUnderTen = 0; partialOverTen = 0; noLogin = 0;
%% Identify which category their completion status falls in if completedModules == 0; totalCompleted = totalCompleted +1; elseif completedModules < 5; partialUnderFive = partialUnderFive +1; elseif 10 > completedModules >= 5 partialUnderTen = partialUnderTen +1; elseif completedModules > 10 partialOverTen = partialOverTen +1; else noLogin = noLogin+1; end %% Calculate Participant Payments
if completedModules == 0; payment = 189.07 elseif completedModules ==13; payment = ((completedModules 1)*11.16) + (completedBlocks * (11.16/16)) else payment = ((completedModules 1) * 11.16)+ (completedBlocks *.36) end
log(a,2) = mat2cell(completedModules); log(a,3) = mat2cell(completedBlocks); log(a,4) = mat2cell(payment); log(a,1) = (username(a));
a=a+1;
end
%% Show Values and Generate Statistics Log %Displays values in MATLAB Command Window
totalCompleted partialUnderFive partialUnderTen partialOverTen noLogin
*** PROBLEM 2 HERE*** %Stores Variable Data in a Matrix colHeader = {'Number Full Completion','Number Partial Completion Less than Five','Number Partial Completion Less than Ten','Number Partial Completion More than Ten','Number No Login'}; stats(1) = (totalCompleted); stats(2) = (partialUnderFive); stats(3) = (partialUnderTen); stats(4) = (partialOverTen);
%% Saves Data into an xls spreadsheet saveName = ['Module_Status_Report' date] xlswrite(saveName,log,1) xlswrite(saveName,stats,2,'A2') xlswrite(saveName,colHeader,2,'A1') end



