Specify nature/type of property
1 回表示 (過去 30 日間)
古いコメントを表示
Hello,
I am writing a class in which I have the property 'food'. The property should be composed of a string specifying the type of food and a double specifying the number of calories. How do I specify this to the property? (As an example, just as I have specified 'string' to 'colour', I want to specify something for 'food')
classdef meals
properties
food
colour string
end
end
Thank you in advance for your help!
回答 (2 件)
Wan Ji
2021 年 8 月 23 日
First define the food class
Then define meals class
Now run meals in the command window, we get empty class meals with two field properties: food and colour
After that, look into this empty meals named ans
And see ans.food by double click it, food type and calories are there
0 件のコメント
per isakson
2021 年 8 月 25 日
編集済み: per isakson
2021 年 8 月 25 日
... or something like:
classdef meals
properties
food (1,1) struct = struct( 'type',{'wheat'}, 'calories',{123} );
colour string
end
end
>> m.food
ans =
struct with fields:
type: 'wheat'
calories: 123
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!