I keep getting parse error when I try and run this script, why?

6 visualizaciones (últimos 30 días)
%Assignment 4 for SES 619 by Ethan Postans
%Fall 2018, Dr. Smith
load data_set1.dat
Column1 - height(cm)
Column2 - mass(kg)
Column3 - body fat(kg)
height = data_set1(:,1);
mass = data_set1(:,2);
fat = data_set1(:,3);
figure(1) %tells matlab to create figure 1
clf reset; %clears and resets figure 1
plot(height, mass, '.'); %plots points
xlabel('subject height (cm)'); %adds label to x-axis
ylabel('subject mass (kg)'); %adds label to y axis
title('Height vs Mass'); %adds title
figure(2) %tells matlab to create figure 2
clf reset; %clears and resets figure 2
plot(height,fat,'.'); %plots points
xlabel('Subject height (cm)'); %adds label to x-axis
ylabel('Subject body fat (kg)'); %adds label to y-axis
title('Height vs Body Fat'); %adds title
The Column3 line is where Matlab is telling me that I have a parse error.
  1 comentario
Ethan Postans
Ethan Postans el 3 de Dic. de 2018
Column1: EMG data for vastus lateralis muscle of the right leg.
COlumn2: EMG data for the vastus lateralis muscle of the left leg.
I also get a parse error for the word data in another section of the assignment

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 3 de Dic. de 2018
Column1 - height(cm)
is a request to find a variable named Column1 or to execute aa function named Column1 and return the result into the expression . Then a variable named cm is to be found or aa function named cm is to be executed to return aa value . with the value of the variable or function in hand, look for aa variable named height and index the variable with the value of cm , but otherwise look for aa function named height and execute it passing in the result of cm. The result of height(cm) is then to be subtracted from the Column1 result. With no semicolon at the end of the line the result is to be displayed .
This is syntactically valid and could work .
Your third line starts with aa subtraction of body from Column3 but then after that there is a space and fat(kg) . The fat(kg) part is syntactically valid being an indexing of aa variable or calling aa function . The problem is that there is no implied multiplication or space operation in MATLAB .
You need to put aa comma between body and fat or else you need to put [ before Column3 and ] after fat(kg)
[Column3 - body fat(kg)]

Más respuestas (0)

Categorías

Más información sobre Labels and Annotations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by