What does this error mean?

1 view (last 30 days)
S
S on 9 Nov 2014
Commented: S on 9 Nov 2014
I keep getting an error saying that there is an "Unbalanced or unexpected parenthesis or bracket." This is the line I keep getting error on. What am I doing wrong?
for data(:,1:end)

Accepted Answer

Geoff Hayes
Geoff Hayes on 9 Nov 2014
The problem is the code is incorrectly defined for a for loop. If the intent is to iterate through each element of data(:,1:end), then your code should be written as
numRows = size(data,1);
for k=1:numRows
% get the kth row of data
rowData = data(k,:);
% do something with the row data
end
If that is not the intent of the code, then please describe what you are trying to do.
  2 Comments
S
S on 9 Nov 2014
It is for one of my homework assignments.
Consider a cell of strings containing gender and height information of some patients (but the data is a little bit messy). Gender is given as 'f','female','m' or 'male' and heights are given in feet or centimeter (some data point are missing). For example
{'f' 'm' 'f' 'female' 'male'; '5.9' '6' '172' '' '180' };
Write a function m=heightconvert(data) to convert the cell array data to a matrix of double m. Use 0 to represent female, 1 to represent male. And convert height into meters and represent any missing data points as NaN. Assume that any height value that is less than 10 is in feet and you need the convert those values to meters using 1 foot = 0.3048 meter. Use str2double() function to convert a string to a number.
S
S on 9 Nov 2014
This is what I have so far. Where am I going wrong?
function [ v ] = heightconvert( data )
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
[~,n]=size(data);
v=zeros(2,n);
for k=data(:,1:end);
v=data(1,1:end);
if strcmp(v,'m') | strcmp(v,'male')
strcmp(v,'m')== v(1,1:end) | strcmp(v,'male')== v(1,1:end);
end
end
for j=data(:,1:end)
v=data(2,1:end);
w=str2double(v);
if w<10
x=w*0.3048;
x=v(2,1:end);
else w>10
x=w*0.01;
x=v(2,1:end);
end
end
end

Sign in to comment.

More Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!