1

I am creating a utility which will give the user a prompt and ask for their crn #, section #, and teacher last name. Once entered the user will receive their exam time, date, and location. I am having an issue with my excel spreadsheet and using a mac os. the script works to completion though the date shows up as just a (.) rather than something like (01/01/0001)

here is the code

here is the spreadsheet to make code work; https://www.dropbox.com/s/drwmk1dinbfwfvl/DrexelFinalsWinter13.xlsx?m

close all;

%% I created an Excel file to hold the information located on Drexel's 
%% website witch contains exam times and locations based on certain criteria
%% First I have to make code to read the excel file created
clc
[ndata, text, alldata]=xlsread('DrexelFinalsWinter13.xlsx');
%% Next we will prompt the user for specific data by creating a dialog box 
%% using the prompt command.
clc
prompt={'Your CRN #','Your Section #',...
    ' Your Instructors Name' };
numlines=1;
defaultanswer={'22081','001','Hawkins'};
name='Enter Info';
options.Resize='on';
options.WindowStyle='normal';
options.Interpreter='tex';
answer=inputdlg(prompt,name,numlines,defaultanswer); %prompt user for data

 a1=cell2mat(answer(1));c1=str2double(a1); %converting cell info to numeric
 a2=cell2mat(answer(2));c2=str2double(a2); %converting cell info to numeric
 w=0;



for p=1:1032;
if (isequal(c1,cell2mat(alldata(p,1))) && ...
        (or(isequal(c2,cell2mat(alldata(p,4))),...
        isequal(answer(2),alldata(p,4)))) && ...
        isequal(answer(3),alldata(p,6))); % the if condition looks to see if
                                          % our input matches any data in the table
   % we cant use cell data below for comoarison so I had to
   % convert it to matlab common data like num or double
   % for numbers because the xlsread function cant
   % distinguish them and only know strings
    w = w+1;
    date = cell2mat(alldata(p,7));
    time = cell2mat(alldata(p,8));
    loca = cell2mat(alldata(p,9)); 
   fprintf('Your exam date is %s. \n',date); % print date results
   fprintf('Your exam time is %s. \n',time);  % print time results
   fprintf('Your exam location is %s. \n',loca); % print location results
   disp('Good luck with your exams! Sleep well & eat a healthy breakfast!'); % just for kicks
elseif p==1032 && w==0   %if we didnt find any matches from our prompt
    'You have provided wrong data or no exam is scheduled for your class.';
end
 end
% The outputs are then located in the command line like below
% answer to the defult values
% Your exam date is 3/19/2013. 
% Your exam time is 0800-1000. 
% Your exam location is See Department. 
% Good luck with your exams! Sleep well & eat a healthy breakfast!
3
  • what is the value of date just before fprintf('Your exam date is %s. \n',date); ? Please check with the debugger Commented Mar 6, 2013 at 14:53
  • in the variables window after I just do the command date = cell2mat(alldata(p,7)); it shows it as just a number like 413566 and not the date. it's an issue with the excel spreadsheet Commented Mar 6, 2013 at 14:58
  • So you need to convert that number to a date string before fprintf will display a date. Excel uses its own funny date convention too so I doubt datenum etc in matlab will solve it but I'm sure you can find online an algorithm for converting excel dates to strings. Commented Mar 6, 2013 at 15:01

1 Answer 1

2

Try this:

fprintf('Your exam date is %s. \n',datestr(x2mdate(date))); % print date results

Have a look at the x2mdate docs if you have the financial toolbox otherwise you can do this:

fprintf('Your exam date is %s. \n',datestr(date + datenum('30DEC1899')));

(from here)

Sign up to request clarification or add additional context in comments.

3 Comments

That's great if the OP has Financial Toolbox.
I do not have financial toolbox unfortunately. The second solution fixed my issue though, Thank You!
Not a problem, please do mark it as solved then by clicked the outline of the tick to the left of this answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.