Cell contents reference from a non-cell array object?
古いコメントを表示
function [ information ] = printInfo( subjects )
s=height(struct2table(subjects));
for x=1:s
name=subjects(x).name;
weight=subjects(x).weight;
maxweight=max(weight);
feet=subjects(x).height.feet;
inches=subjects(x).height.inches;
str='%d: %d''%d", %d pounds';
information=sprintf(str,name,feet,inches,maxweight);
end
end
4 件のコメント
Birdman
2018 年 3 月 6 日
What is your input to the function?
Garrett Miller
2018 年 3 月 6 日
編集済み: per isakson
2018 年 3 月 6 日
Walter Roberson
2018 年 3 月 6 日
Which line is the error occurring on?
You should probably be replacing the assignment to s with
s = numel(subjects);
Garrett Miller
2018 年 3 月 6 日
編集済み: per isakson
2018 年 3 月 6 日
回答 (2 件)
per isakson
2018 年 3 月 6 日
編集済み: per isakson
2018 年 3 月 6 日
yourInfo is a character array, not a cell array, thus replace
yourInfo{ string }
by
yourInfo( string )
After done that correction your code produces a plot and no errors.
btw: string is a poor name of a loop-variable - IMO
Walter Roberson
2018 年 3 月 7 日
編集済み: Walter Roberson
2018 年 3 月 7 日
function [ information ] = printInfo( subjects )
s=numel(subjects);
for x=1:s
name=subjects(x).name;
weight=subjects(x).weight;
maxweight=max(weight);
feet=subjects(x).height.feet;
inches=subjects(x).height.inches;
str='%s: %d''%d", %d pounds';
information{x}=sprintf(str,name,feet,inches,maxweight);
end
end
カテゴリ
ヘルプ センター および File Exchange で Cell Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!