The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Problems with Strings!
Replies: 4   Last Post: Jun 25, 2013 8:34 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 20
Registered: 12/7/10
Problems with Strings!
Posted: Jun 25, 2013 3:16 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply


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);

x = strcat(input('Enter usernames for current cohort','s'));
userNames = strsplit(x)

%% 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;
noLogin = noLogin+1;

%% Calculate Participant Payments

if completedModules == 0;
payment = 189.07
elseif completedModules ==13;
payment = ((completedModules -1)*11.16) + (completedBlocks * (11.16/16))
payment = ((completedModules -1) * 11.16)+ (completedBlocks *.36)

log(a,2) = mat2cell(completedModules);
log(a,3) = mat2cell(completedBlocks);
log(a,4) = mat2cell(payment);
log(a,1) = (username(a));



%% Show Values and Generate Statistics Log
%Displays values in MATLAB Command Window


%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]

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.