How to use feval to call a class

8 ビュー (過去 30 日間)
Riccardo Micci
Riccardo Micci 2022 年 8 月 15 日
コメント済み: Riccardo Micci 2022 年 8 月 15 日
I have several classes all with same interface and i have to call them according to user input. I don't wat to create a switch case since i'll need to update the code for every new class that is created. I'd like to use the feval instead so the only check i need to make is that the file exists.
I can't find a way to make it work with classes, only with functions.
Example:
filename: dummyclass.m
classdef dummyclass < handle
properties
end
methods
function [state] = create(obj, ...)
bla bla
end
end
end
main function call: main_func('dummyclass')
function main_func(name)
feval([name '.create'])
bla bla
end
The above doesn't work, it's just an idea of what i'd like to achieve. How can i automatically call 'dummyclass.create()'?
Thanks

採用された回答

Walter Roberson
Walter Roberson 2022 年 8 月 15 日
feval(name).create
  1 件のコメント
Riccardo Micci
Riccardo Micci 2022 年 8 月 15 日
Thanks!!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeManual Performance Optimization についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by