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

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2011년 7월 11일

2 개 추천

bayesPosParams.distribution = {'normal'; 'kernel'};
bayesPosParams.prior = {'empirical'; 'uniform'};
bayesPosParams.KSWidth = 'scalar';
bayesPosParams.KSSupport = {'unbounded'; 'positive'};

추가 답변 (1개)

Jay
Jay 2011년 7월 11일

1 개 추천

Hi Andrei!
Then every field would be a cell array, correct? What's the differences between this approach and using, my just discovered method, bayesPosParams.distribution = char('normal', 'kernel')?
I will want to operate on bayesPosParams with for-loops.
Thanks!

댓글 수: 6

Jan
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
Andrei Bobrov 2011년 7월 11일
Thanks Jan, I full agree with Jan
Jay
Jay 2011년 7월 11일
hi, thanks a lot!
If I'd do:
for dis = bayesPosParams.distribution
then dis would become 1x1 cellarrays ( {normal} and {kernel} ) right?
How can I get dis to get the two chararrays 'normal' and 'kernel'?
Thanks again,
Jay
Andrei Bobrov
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
Jay 2011년 7월 12일
right, i want to test all possible combinations of parameters.
only way i could think of is to do this with four nested for-loops. Probably very slow, but don't know how to do that else.
So I would for example want to iterate over all chararray-values of bayesPosParams.distribution, namely 'normal' and 'kernel'.
How do I do that?
Something like:
for dis = bayesPosParams.distribution{}
....
but this does not seem right either...
Andrei Bobrov
Andrei Bobrov 2011년 7월 12일
dis - cell array, and may be any operation with 'dis', as with cellarrays

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

질문:

Jay
2011년 7월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by