Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can anyone help. I keep on getting these errors Warning: Successfully read the d

ID: 3662410 • Letter: C

Question

Can anyone help. I keep on getting these errors

Warning: Successfully read the date/time strings using the format 'MM/dd/uuuu', but their format is
ambiguous and could also be 'dd/MM/uuuu'. Specify a format string to avoid ambiguity.


Error using textscan
The second input must be a format string containing at least one specifier or a literal field.

Error in loadSolarData (line 17)
sunTimeMatrix=textscan(fid,dv);

This is my function.

function[sunData,sunTimeMatrix]=loadSolarData(mntNo)

mntNo=menu('Choose a month','January','February','March','April',...
'May','June','July','August','September','October','November',...
'December');
  
switch mntNo
  
case 1
fid = fopen('Jan.csv','r');
global data1
data1 = textscan(fid,'%s %s %s %s','Delimiter',',','CollectOutput',...
true,'HeaderLines',2);
data1 = strrep(data1{1},'"','');
t=datetime(data1(1:2),'Format','MM/dd/uuuu');
dv=datevec(t);
sunTimeMatrix=textscan(fid,dv);
sunData=sum(IG2+IG3)/2.0;
fclose(fid);
assignin('base', 'sunData', sunData);
assignin('base', 'sunTimeMatrix', sunTimeMatrix);

case 2 etc

Explanation / Answer

For your refernce : To create a LocalDateTime object from a string you can use the static Local DateTime parse method. It takes a string and a Date Time Formatter as parameter. The DateTimeFormatter is used to specify the date/time pattern.

String str = "2000-74-08 11:40";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
LocalDateTime dateTime = LocalDateTime.parse(str, formatter);