フィルターのクリア

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 Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by