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

조회 수: 7 (최근 30일)
Ethan Postans
Ethan Postans 2018년 12월 3일
답변: Walter Roberson 2018년 12월 3일
%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
Ethan Postans
Ethan Postans 2018년 12월 3일
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

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2018년 12월 3일
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)]

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Labels and Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by