フィルターのクリア

I'm getting >> Reference to non-existent field 'speak'. error. Please help.

1 回表示 (過去 30 日間)
Ishan Gawai
Ishan Gawai 2021 年 3 月 8 日
コメント済み: Ishan Gawai 2021 年 3 月 9 日
Hi, I'm a beginner in matlab and using OO programming for first time. Whenever I call function speak from class I get reference to non-existent field 'speak ' error.
classdef dog
properties
name
breed
colour
end
methods
function speak(obj)
disp(obj.name + "says Hi!!!")
end
end
end

採用された回答

Cris LaPierre
Cris LaPierre 2021 年 3 月 8 日
Your code is fine. Make sure you create an instance of the class, then use that when calling your method. See here.
c=dog;
c.name = "Ruby";
speak(c)
Rubysays Hi!!!
c.speak
Rubysays Hi!!!

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSoftware Development Tools についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by