필터 지우기
필터 지우기

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