Structure of Strings
显示 更早的评论
Hi!
I want to specify possible parameters for the naive bayes classifier. For this reason, I have created a structure with a field for each parameter and a matrix with possible values.
bayesPosParams.distribution = ['normal'; 'kernel'];
bayesPosParams.prior = ['empirical'; 'uniform'];
bayesPosParams.KSWidth = 'scalar';
bayesPosParams.KSSupport = ['unbounded'; 'positive'];
Unfortunately that does not work: ??? Error using ==> vertcat CAT arguments dimensions are not consistent.
All Strings need to have the same length. What would be the best possibility to specify the parameters nice and consistently?
Thanks in advance, Jay
采纳的回答
更多回答(1 个)
Jay
2011-7-11
1 个投票
6 个评论
Jan
2011-7-11
Using CHAR creates a rectangular matrix by padding shorter strings with spaces. Then comparing a row of the matrix with STRCMP is harder, because the trailing spaces have to be considered. Therefore the cell string is more comfortable and more efficient:
CHAR: unblank(bayesPosParams.distribution(i, :))
CELLSTRING: bayesPosParams.distribution{i}
Andrei Bobrov
2011-7-11
Thanks Jan, I full agree with Jan
Jay
2011-7-11
Andrei Bobrov
2011-7-12
no, dis would become 2x1 cellarrays
>> dis = bayesPosParams.distribution
dis =
'normal'
'kernel'
>> dis{1} % call char array
ans =
normal
>> dis{2} % call char array
ans =
kernel
Jay
2011-7-12
Andrei Bobrov
2011-7-12
dis - cell array, and may be any operation with 'dis', as with cellarrays
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!