Please help! Matrix Dimensions GUI Method Error

1 view (last 30 days)
I am a high school senior and this is my first time creating a GUI in MATLAB. I'm trying to create a GUI where you can enter your age, weight, height, etc. and it will "assess" your choices. I'm running into errors when calling the methods. It keeps informing me that "Matrix Dimensions Must Agree" although I made sure all inputs are scalar doubles. I have left several other comments on lines of code that I am confused about, where although they do not seem to match with the variables at hand the app still compiles past those parts.
I have attatched a zip file containing my app as well as the four functions the app requires. Thank you!

Accepted Answer

Chidvi Modala
Chidvi Modala on 31 Mar 2021
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.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!