Variable size class properties for C++ code export

Dear all,
I would like to use a class as input to a function that is later exported to C++-code.
Something like:
classdef inputClass
properties
var(:, 1)
b = 0
end
end
Here var(:, 1) means, that I want var to be of variable size. However, as soon as I use var the coder complains about mismatching sizes, stating that var is of size 0x1. Can I somehow declare a class property to be of variable size? According to the page here, coder.varsize does not work.
Thanks in advance
Torsten

3 Kommentare

Guillaume
Guillaume am 10 Jul. 2019
I don't know much about coder (don't have the toolbox), but reading the page you link, I'm not sure that you can have variable size class properties. However, that page is really lacking in details.
In any case, you certainly don't have to specify the (:, 1) since I doubt that coder generates the required property validation code anyway.
winkmal
winkmal am 14 Aug. 2019
Which Matlab version are you on? I don't have Coder either, but this reminds me very much of a problem I had some time ago, which turned out to be a bug! This was in R2017b, so it should be fixed by now. Read here for details.
Viet Nguyen
Viet Nguyen am 10 Mär. 2020
Did you end up getting this resolved? I am running into the same error.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Sayyed Ahmad
Sayyed Ahmad am 10 Jul. 2019
The defination of var is wrong.
it's ok if you write
classdef inputClass
properties
var;
b = 0
end
methods
function o = inputClass(varargin)
if nargin == 2
o.var = varargin{1};
o.b= varargin{2};
else
error("the nuber of arguments do not match!")
end
end
end
end
>>x=inputClass([1 2 3],2)
x =
inputClass with properties:
var: [1 2 3]
b: 2

2 Kommentare

Guillaume
Guillaume am 10 Jul. 2019
Bearbeitet: Guillaume am 10 Jul. 2019
"The defination of var is wrong."
From a pure matlab point of view (ignoring coder), there is nothing wrong with the definition of var. Can you explain what you mean by that?
you can def. a variable without dimension or a fix dimension. But a def. like var(:,1) could not be handel by compeiler.
Compeiler could be handel a calling of variable by var(:,1) but not the def. of variable.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Argument Definitions finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 10 Jul. 2019

Kommentiert:

am 10 Mär. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by