From a high level observation, few points can be noted
- Casting a character array to double using "double()" will give you its ASCII values. For example the following code is taken from dailyAssessment.mlapp, line 163. Here user entered value is 100. then app.EnterWorkoutTime.Value will be '100' which is a character array. When you try to cast it to double, it gives you its ASCII values. So, app.workoutTime will be [49 48 48] (ASCII value of '1' is 49 and '0' is 48)
function EnterWorkoutTimeValueChanged(app, event)
value = app.EnterWorkoutTime.Value;
app.workoutTime = double(value);
app.workoutTime1 = double(value);
end
So you may replace double with str2double
function EnterWorkoutTimeValueChanged(app, event)
value = app.EnterWorkoutTime.Value;
app.workoutTime = str2double(value);
app.workoutTime1 = str2double(value);
end
- In dailyHealth.m file, line 23, it is comparing a char array (workoutTime = [49 48 48]) with a scalar 30. Hence the error. So the above replacement can solve this error
if ((workoutTime >= 30) && (contains(workoutDesc,'Moderate'))) || ((workoutTime >= 15) && (contains(workoutDesc,'Vigorous')))
assessWorkout = workoutAssessmentAnswers(1);
else
assessWorkout = workoutAssessmentAnswers(2);
end
- Based on the given code, the entered value will be stored only when the user changes the value from the given default value. For example, the following code is taken from dailyAssessment.mlapp, line 153
function ChooseSexSelectionChanged(app, event)
selectedButton = app.ChooseSex.SelectedObject;
if selectedButton == app.MaleButton
app.sex = 'M';
else
app.sex = 'W';
end
end
Initially the default value is set to 'M' If the user doesn't change it, then the above code doesn't execute, so app.sex will not be defined .
- Just a suggestion, you can set a breakpoint wherever the error is occuring, and observe the workspace values to debug your issues. Here is a link that explains how to set a breakpoint.