I want to use a structure as a global variable. This code is an example of the function:
function setGlobalx()
global measBuff
measBuff(1:6) = struct('timeUtc',1,'timePeakOff',2,'peak',3,'mean',4,'eventT',5);
If I call it using:
setGlobalx
global measBuff
display(measBuff)
I get an error on line 3 of the function:
The following error occurred converting from struct to double:
Error using double
Conversion to double from struct is not possible.
Error in setGlobalx (line 3)
measBuff(1:6) = struct('timeUtc',1,'timePeakOff',2,'peak',3,'mean',4,'eventT',5);
Error in Untitled7 (line 3)
setGlobalx
However, if I change the function to:
function setGlobalx2()
measBuff(1:6) = struct('timeUtc',1,'timePeakOff',2,'peak',3,'mean',4,'eventT',5);
global x
x=measBuff
and run
setGlobalx2
global x
display(x);
I get no errors and the structure x is global.
Can anyone tell me why the first method doesn't work? Thanks.
0 件のコメント
サインインしてコメントする。