Why do I get an "Invalid value returned."-error when assigning a string property inside a loop using v18b?
显示 更早的评论
When initializing an object of class "Matlab_Dbl_Str_Test" (class in attached file below) in Matlab v18b the result is the following:

When avoiding the try catch block one gets the above mentioned error.
It appears that properties of type string cannot be assigned in a loop whereas properties of type double are perfectly fine.
Is this a known bug or wanted feauture?
%% --------------------------------------------------------------------------
classdef Matlab_Dbl_Str_Test < handle
%UNTITLED2 Summary of this class goes here
% Detailed explanation goes here
properties( Constant )
TEST_STR = ["a";"b";"c"];
TEST_DBL = [0;1;2];
end
properties( SetAccess = protected )
test_str@string as vector;
test_dbl@double as vector;
end
methods
function obj = Matlab_Dbl_Str_Test()
for i = 1:3
try obj.test_str(i) = Matlab_Dbl_Str_Test.TEST_STR(i,1);end
try obj.test_dbl(i) = Matlab_Dbl_Str_Test.TEST_DBL(i,1);end
end
end
function test( obj )
for i = 1:3
try obj.test_str(i) = Matlab_Dbl_Str_Test.TEST_STR(i,1);end
try obj.test_dbl(i) = Matlab_Dbl_Str_Test.TEST_DBL(i,1);end
end
end
end
end
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Operations on Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!