What does this error mean?

1 次查看(过去 30 天)
S
S 2014-11-9
评论: S 2014-11-9
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)

采纳的回答

Geoff Hayes
Geoff Hayes 2014-11-9
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 个评论
S
S 2014-11-9
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 2014-11-9
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by