이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
Input or put a large array of numbers into a function
조회 수: 2 (최근 30일)
이전 댓글 표시
I'm fairly new to MATLAB. My assignment is to pick a word, break it down into each letter, generate all the possibilities with replacement of all the letters, assign each letter with a probability, calculate the their probabilities in 3rd, 4th, and 5th order extenstion, and use the built-in huffmandict function to generate the binary equivalence of each symbol.
In my case, I picked the word 'locate', so each letter will be 'l' 'o' 'c' 'a' 't' 'e'.
3rd order extension means combination of 3 letters. For instance, 'loc' 'loa' 'lot' etc... The same goes for 4th and 5th order. So 3rd order will have 216 possible combinations, 4th order will have 1296 and 5th will have 7776 combinations.
From my thought process to approach this problem, here is what I have so far:
I used the COMBINATOR function that I found to generate all the possible combinations
n3 = combinator(6, 3, 'p', 'r'); % 3rd order possible combinations
n4 = combinator(6, 4, 'p', 'r'); % 4th order possible combinations
n5 = combinator(6, 5, 'p', 'r'); % 5th order possible combinations
then I move the outputs of n3, n4, and n5 to Excel, replace the number with the letters (1 = l , 2 = o , 3 = c , 4 = a, 5 = t , 6 = e) , then replace them again with assigned probabilities (l = 0.1 , o = 0.18 , c =0.02 , a = 0.4 , t = 0.08 , e = 0.22), calcalate the probabilities for each symbol by the product of all the letter in that symbol. For instance, 3rd order, 'loc', will be 0.1*0.18*0.02 = 0.00036. I'm currently stuck at how to move back all 216, 1296 or 7776 probabilties to MATLAB to use the huffmandict function. The function requires 2 arguments, numbers of symbols and their corresponding probabilities.
I hope this makes sense. Any advice, help, tip or guidance will be appreciated. I know all of these can be done on MATLAB, but I'm not fluent in the programming language. Main reason that I involved Excel.
댓글 수: 3
the cyclist
2022년 10월 28일
Can you upload the code? You can use the paper clip icon in the INSERT section of the toolbar. Reading your description is not as useful as seeing the code.
Ben Nguyen
2022년 10월 28일
n3 = combinator(6, 3, 'p', 'r');
n4 = combinator(6, 4, 'p', 'r');
n5 = combinator(6, 5, 'p', 'r');
Ben Nguyen
2022년 10월 28일
That's all I had for my code. My next step is to transfer all the outputs of n3, n4, n5 to Excel spreasheets manually. Since the combinator function output the combinations only in numbers, I will replace the numbers with letters in Excel manually.
채택된 답변
David Hill
2022년 10월 28일
x='locate';prob=[.1 .18 .02 .4 .08 .22];
p=[];order=3;
n=nchoosek(1:length(x),order);
for k=1:size(n,1)
p=[p;perms(n(k,:))];
end
X=x(p)
X = 120×3 char array
'col'
'clo'
'ocl'
'olc'
'lco'
'loc'
'aol'
'alo'
'oal'
'ola'
'lao'
'loa'
'tol'
'tlo'
'otl'
'olt'
'lto'
'lot'
'eol'
'elo'
'oel'
'ole'
'leo'
'loe'
'acl'
'alc'
'cal'
'cla'
'lac'
'lca'
'tcl'
'tlc'
'ctl'
'clt'
'ltc'
'lct'
'ecl'
'elc'
'cel'
'cle'
'lec'
'lce'
'tal'
'tla'
'atl'
'alt'
'lta'
'lat'
'eal'
'ela'
'ael'
'ale'
'lea'
'lae'
'etl'
'elt'
'tel'
'tle'
'let'
'lte'
'aco'
'aoc'
'cao'
'coa'
'oac'
'oca'
'tco'
'toc'
'cto'
'cot'
'otc'
'oct'
'eco'
'eoc'
'ceo'
'coe'
'oec'
'oce'
'tao'
'toa'
'ato'
'aot'
'ota'
'oat'
'eao'
'eoa'
'aeo'
'aoe'
'oea'
'oae'
'eto'
'eot'
'teo'
'toe'
'oet'
'ote'
'tac'
'tca'
'atc'
'act'
'cta'
'cat'
'eac'
'eca'
'aec'
'ace'
'cea'
'cae'
'etc'
'ect'
'tec'
'tce'
'cet'
'cte'
'eta'
'eat'
'tea'
'tae'
'aet'
'ate'
P=prod(prob(p),2)
P = 120×1
0.0004
0.0004
0.0004
0.0004
0.0004
0.0004
0.0072
0.0072
0.0072
0.0072
댓글 수: 6
Ben Nguyen
2022년 10월 28일
This will work with the without replacement combinations. nchoosek only produces 120 combinations.
Walter Roberson
2022년 10월 29일
but the code uses perms() to ensure that all of the permutations are generated.
Ben Nguyen
2022년 10월 29일
But I do need all 216 possibilies, so my total probabilties will add upto 1. Huffmandict function only works when the total probabilities of all symbols are added to be 1.
David Hill
2022년 10월 29일
x='locate';prob=[.1 .18 .02 .4 .08 .22];
[a,b,c]=ndgrid(1:length(x));%for order 3, increase for higher orders
[d,e,f,g]=ndgrid(1:length(x));%for order 4
idx=[a(:),b(:),c(:)];
idx2=[d(:),e(:),f(:),g(:)];
w=x(idx)
w = 216×3 char array
'lll'
'oll'
'cll'
'all'
'tll'
'ell'
'lol'
'ool'
'col'
'aol'
'tol'
'eol'
'lcl'
'ocl'
'ccl'
'acl'
'tcl'
'ecl'
'lal'
'oal'
'cal'
'aal'
'tal'
'eal'
'ltl'
'otl'
'ctl'
'atl'
'ttl'
'etl'
'lel'
'oel'
'cel'
'ael'
'tel'
'eel'
'llo'
'olo'
'clo'
'alo'
'tlo'
'elo'
'loo'
'ooo'
'coo'
'aoo'
'too'
'eoo'
'lco'
'oco'
'cco'
'aco'
'tco'
'eco'
'lao'
'oao'
'cao'
'aao'
'tao'
'eao'
'lto'
'oto'
'cto'
'ato'
'tto'
'eto'
'leo'
'oeo'
'ceo'
'aeo'
'teo'
'eeo'
'llc'
'olc'
'clc'
'alc'
'tlc'
'elc'
'loc'
'ooc'
'coc'
'aoc'
'toc'
'eoc'
'lcc'
'occ'
'ccc'
'acc'
'tcc'
'ecc'
'lac'
'oac'
'cac'
'aac'
'tac'
'eac'
'ltc'
'otc'
'ctc'
'atc'
'ttc'
'etc'
'lec'
'oec'
'cec'
'aec'
'tec'
'eec'
'lla'
'ola'
'cla'
'ala'
'tla'
'ela'
'loa'
'ooa'
'coa'
'aoa'
'toa'
'eoa'
'lca'
'oca'
'cca'
'aca'
'tca'
'eca'
'laa'
'oaa'
'caa'
'aaa'
'taa'
'eaa'
'lta'
'ota'
'cta'
'ata'
'tta'
'eta'
'lea'
'oea'
'cea'
'aea'
'tea'
'eea'
'llt'
'olt'
'clt'
'alt'
'tlt'
'elt'
'lot'
'oot'
'cot'
'aot'
'tot'
'eot'
'lct'
'oct'
'cct'
'act'
'tct'
'ect'
'lat'
'oat'
'cat'
'aat'
'tat'
'eat'
'ltt'
'ott'
'ctt'
'att'
'ttt'
'ett'
'let'
'oet'
'cet'
'aet'
'tet'
'eet'
'lle'
'ole'
'cle'
'ale'
'tle'
'ele'
'loe'
'ooe'
'coe'
'aoe'
'toe'
'eoe'
'lce'
'oce'
'cce'
'ace'
'tce'
'ece'
'lae'
'oae'
'cae'
'aae'
'tae'
'eae'
'lte'
'ote'
'cte'
'ate'
'tte'
'ete'
'lee'
'oee'
'cee'
'aee'
'tee'
'eee'
s=sum(prod(prob(idx),2))%sum of all probs
s = 1
w2=x(idx2)
w2 = 1296×4 char array
'llll'
'olll'
'clll'
'alll'
'tlll'
'elll'
'loll'
'ooll'
'coll'
'aoll'
'toll'
'eoll'
'lcll'
'ocll'
'ccll'
'acll'
'tcll'
'ecll'
'lall'
'oall'
'call'
'aall'
'tall'
'eall'
'ltll'
'otll'
'ctll'
'atll'
'ttll'
'etll'
'lell'
'oell'
'cell'
'aell'
'tell'
'eell'
'llol'
'olol'
'clol'
'alol'
'tlol'
'elol'
'lool'
'oool'
'cool'
'aool'
'tool'
'eool'
'lcol'
'ocol'
'ccol'
'acol'
'tcol'
'ecol'
'laol'
'oaol'
'caol'
'aaol'
'taol'
'eaol'
'ltol'
'otol'
'ctol'
'atol'
'ttol'
'etol'
'leol'
'oeol'
'ceol'
'aeol'
'teol'
'eeol'
'llcl'
'olcl'
'clcl'
'alcl'
'tlcl'
'elcl'
'locl'
'oocl'
'cocl'
'aocl'
'tocl'
'eocl'
'lccl'
'occl'
'cccl'
'accl'
'tccl'
'eccl'
'lacl'
'oacl'
'cacl'
'aacl'
'tacl'
'eacl'
'ltcl'
'otcl'
'ctcl'
'atcl'
'ttcl'
'etcl'
'lecl'
'oecl'
'cecl'
'aecl'
'tecl'
'eecl'
'llal'
'olal'
'clal'
'alal'
'tlal'
'elal'
'loal'
'ooal'
'coal'
'aoal'
'toal'
'eoal'
'lcal'
'ocal'
'ccal'
'acal'
'tcal'
'ecal'
'laal'
'oaal'
'caal'
'aaal'
'taal'
'eaal'
'ltal'
'otal'
'ctal'
'atal'
'ttal'
'etal'
'leal'
'oeal'
'ceal'
'aeal'
'teal'
'eeal'
'lltl'
'oltl'
'cltl'
'altl'
'tltl'
'eltl'
'lotl'
'ootl'
'cotl'
'aotl'
'totl'
'eotl'
'lctl'
'octl'
'cctl'
'actl'
'tctl'
'ectl'
'latl'
'oatl'
'catl'
'aatl'
'tatl'
'eatl'
'lttl'
'ottl'
'cttl'
'attl'
'tttl'
'ettl'
'letl'
'oetl'
'cetl'
'aetl'
'tetl'
'eetl'
'llel'
'olel'
'clel'
'alel'
'tlel'
'elel'
'loel'
'ooel'
'coel'
'aoel'
'toel'
'eoel'
'lcel'
'ocel'
'ccel'
'acel'
'tcel'
'ecel'
'lael'
'oael'
'cael'
'aael'
'tael'
'eael'
'ltel'
'otel'
'ctel'
'atel'
'ttel'
'etel'
'leel'
'oeel'
'ceel'
'aeel'
'teel'
'eeel'
'lllo'
'ollo'
'cllo'
'allo'
'tllo'
'ello'
'lolo'
'oolo'
'colo'
'aolo'
'tolo'
'eolo'
'lclo'
'oclo'
'cclo'
'aclo'
'tclo'
'eclo'
'lalo'
'oalo'
'calo'
'aalo'
'talo'
'ealo'
'ltlo'
'otlo'
'ctlo'
'atlo'
'ttlo'
'etlo'
'lelo'
'oelo'
'celo'
'aelo'
'telo'
'eelo'
'lloo'
'oloo'
'cloo'
'aloo'
'tloo'
'eloo'
'looo'
'oooo'
'cooo'
'aooo'
'tooo'
'eooo'
'lcoo'
'ocoo'
'ccoo'
'acoo'
'tcoo'
'ecoo'
'laoo'
'oaoo'
'caoo'
'aaoo'
'taoo'
'eaoo'
'ltoo'
'otoo'
'ctoo'
'atoo'
'ttoo'
'etoo'
'leoo'
'oeoo'
'ceoo'
'aeoo'
'teoo'
'eeoo'
'llco'
'olco'
'clco'
'alco'
'tlco'
'elco'
'loco'
'ooco'
'coco'
'aoco'
'toco'
'eoco'
'lcco'
'occo'
'ccco'
'acco'
'tcco'
'ecco'
'laco'
'oaco'
'caco'
'aaco'
'taco'
'eaco'
'ltco'
'otco'
'ctco'
'atco'
'ttco'
'etco'
'leco'
'oeco'
'ceco'
'aeco'
'teco'
'eeco'
'llao'
'olao'
'clao'
'alao'
'tlao'
'elao'
'loao'
'ooao'
'coao'
'aoao'
'toao'
'eoao'
'lcao'
'ocao'
'ccao'
'acao'
'tcao'
'ecao'
'laao'
'oaao'
'caao'
'aaao'
'taao'
'eaao'
'ltao'
'otao'
'ctao'
'atao'
'ttao'
'etao'
'leao'
'oeao'
'ceao'
'aeao'
'teao'
'eeao'
'llto'
'olto'
'clto'
'alto'
'tlto'
'elto'
'loto'
'ooto'
'coto'
'aoto'
'toto'
'eoto'
'lcto'
'octo'
'ccto'
'acto'
'tcto'
'ecto'
'lato'
'oato'
'cato'
'aato'
'tato'
'eato'
'ltto'
'otto'
'ctto'
'atto'
'ttto'
'etto'
'leto'
'oeto'
'ceto'
'aeto'
'teto'
'eeto'
'lleo'
'oleo'
'cleo'
'aleo'
'tleo'
'eleo'
'loeo'
'ooeo'
'coeo'
'aoeo'
'toeo'
'eoeo'
'lceo'
'oceo'
'cceo'
'aceo'
'tceo'
'eceo'
'laeo'
'oaeo'
'caeo'
'aaeo'
'taeo'
'eaeo'
'lteo'
'oteo'
'cteo'
'ateo'
'tteo'
'eteo'
'leeo'
'oeeo'
'ceeo'
'aeeo'
'teeo'
'eeeo'
'lllc'
'ollc'
'cllc'
'allc'
'tllc'
'ellc'
'lolc'
'oolc'
'colc'
'aolc'
'tolc'
'eolc'
'lclc'
'oclc'
'cclc'
'aclc'
'tclc'
'eclc'
'lalc'
'oalc'
'calc'
'aalc'
'talc'
'ealc'
'ltlc'
'otlc'
'ctlc'
'atlc'
'ttlc'
'etlc'
'lelc'
'oelc'
'celc'
'aelc'
'telc'
'eelc'
'lloc'
'oloc'
'cloc'
'aloc'
'tloc'
'eloc'
'looc'
'oooc'
'cooc'
'aooc'
'tooc'
'eooc'
'lcoc'
'ococ'
'ccoc'
'acoc'
'tcoc'
'ecoc'
'laoc'
'oaoc'
'caoc'
'aaoc'
'taoc'
'eaoc'
'ltoc'
'otoc'
'ctoc'
'atoc'
'ttoc'
'etoc'
'leoc'
'oeoc'
'ceoc'
'aeoc'
'teoc'
'eeoc'
'llcc'
'olcc'
'clcc'
'alcc'
'tlcc'
'elcc'
'locc'
'oocc'
'cocc'
'aocc'
'tocc'
'eocc'
'lccc'
'occc'
'cccc'
'accc'
'tccc'
'eccc'
'lacc'
'oacc'
'cacc'
'aacc'
'tacc'
'eacc'
'ltcc'
'otcc'
'ctcc'
'atcc'
'ttcc'
'etcc'
'lecc'
'oecc'
'cecc'
'aecc'
'tecc'
'eecc'
'llac'
'olac'
'clac'
'alac'
'tlac'
'elac'
'loac'
'ooac'
'coac'
'aoac'
'toac'
'eoac'
'lcac'
'ocac'
'ccac'
'acac'
'tcac'
'ecac'
'laac'
'oaac'
'caac'
'aaac'
'taac'
'eaac'
'ltac'
'otac'
'ctac'
'atac'
'ttac'
'etac'
'leac'
'oeac'
'ceac'
'aeac'
'teac'
'eeac'
'lltc'
'oltc'
'cltc'
'altc'
'tltc'
'eltc'
'lotc'
'ootc'
'cotc'
'aotc'
'totc'
'eotc'
'lctc'
'octc'
'cctc'
'actc'
'tctc'
'ectc'
'latc'
'oatc'
'catc'
'aatc'
'tatc'
'eatc'
'lttc'
'ottc'
'cttc'
'attc'
'tttc'
'ettc'
'letc'
'oetc'
'cetc'
'aetc'
'tetc'
'eetc'
'llec'
'olec'
'clec'
'alec'
'tlec'
'elec'
'loec'
'ooec'
'coec'
'aoec'
'toec'
'eoec'
'lcec'
'ocec'
'ccec'
'acec'
'tcec'
'ecec'
'laec'
'oaec'
'caec'
'aaec'
'taec'
'eaec'
'ltec'
'otec'
'ctec'
'atec'
'ttec'
'etec'
'leec'
'oeec'
'ceec'
'aeec'
'teec'
'eeec'
'llla'
'olla'
'clla'
'alla'
'tlla'
'ella'
'lola'
'oola'
'cola'
'aola'
'tola'
'eola'
'lcla'
'ocla'
'ccla'
'acla'
'tcla'
'ecla'
'lala'
'oala'
'cala'
'aala'
'tala'
'eala'
'ltla'
'otla'
'ctla'
'atla'
'ttla'
'etla'
'lela'
'oela'
'cela'
'aela'
'tela'
'eela'
'lloa'
'oloa'
'cloa'
'aloa'
'tloa'
'eloa'
'looa'
'oooa'
'cooa'
'aooa'
'tooa'
'eooa'
'lcoa'
'ocoa'
'ccoa'
'acoa'
'tcoa'
'ecoa'
'laoa'
'oaoa'
'caoa'
'aaoa'
'taoa'
'eaoa'
'ltoa'
'otoa'
'ctoa'
'atoa'
'ttoa'
'etoa'
'leoa'
'oeoa'
'ceoa'
'aeoa'
'teoa'
'eeoa'
'llca'
'olca'
'clca'
'alca'
'tlca'
'elca'
'loca'
'ooca'
'coca'
'aoca'
'toca'
'eoca'
'lcca'
'occa'
'ccca'
'acca'
'tcca'
'ecca'
'laca'
'oaca'
'caca'
'aaca'
'taca'
'eaca'
'ltca'
'otca'
'ctca'
'atca'
'ttca'
'etca'
'leca'
'oeca'
'ceca'
'aeca'
'teca'
'eeca'
'llaa'
'olaa'
'claa'
'alaa'
'tlaa'
'elaa'
'loaa'
'ooaa'
'coaa'
'aoaa'
'toaa'
'eoaa'
'lcaa'
'ocaa'
'ccaa'
'acaa'
'tcaa'
'ecaa'
'laaa'
'oaaa'
'caaa'
'aaaa'
'taaa'
'eaaa'
'ltaa'
'otaa'
'ctaa'
'ataa'
'ttaa'
'etaa'
'leaa'
'oeaa'
'ceaa'
'aeaa'
'teaa'
'eeaa'
'llta'
'olta'
'clta'
'alta'
'tlta'
'elta'
'lota'
'oota'
'cota'
'aota'
'tota'
'eota'
'lcta'
'octa'
'ccta'
'acta'
'tcta'
'ecta'
'lata'
'oata'
'cata'
'aata'
'tata'
'eata'
'ltta'
'otta'
'ctta'
'atta'
'ttta'
'etta'
'leta'
'oeta'
'ceta'
'aeta'
'teta'
'eeta'
'llea'
'olea'
'clea'
'alea'
'tlea'
'elea'
'loea'
'ooea'
'coea'
'aoea'
'toea'
'eoea'
'lcea'
'ocea'
'ccea'
'acea'
'tcea'
'ecea'
'laea'
'oaea'
'caea'
'aaea'
'taea'
'eaea'
'ltea'
'otea'
'ctea'
'atea'
'ttea'
'etea'
'leea'
'oeea'
'ceea'
'aeea'
'teea'
'eeea'
'lllt'
'ollt'
'cllt'
'allt'
'tllt'
'ellt'
'lolt'
'oolt'
'colt'
'aolt'
'tolt'
'eolt'
'lclt'
'oclt'
'cclt'
'aclt'
'tclt'
'eclt'
'lalt'
'oalt'
'calt'
'aalt'
'talt'
'ealt'
'ltlt'
'otlt'
'ctlt'
'atlt'
'ttlt'
'etlt'
'lelt'
'oelt'
'celt'
'aelt'
'telt'
'eelt'
'llot'
'olot'
'clot'
'alot'
'tlot'
'elot'
'loot'
'ooot'
'coot'
'aoot'
'toot'
'eoot'
'lcot'
'ocot'
'ccot'
'acot'
'tcot'
'ecot'
'laot'
'oaot'
'caot'
'aaot'
'taot'
'eaot'
'ltot'
'otot'
'ctot'
'atot'
'ttot'
'etot'
'leot'
'oeot'
'ceot'
'aeot'
'teot'
'eeot'
'llct'
'olct'
'clct'
'alct'
'tlct'
'elct'
'loct'
'ooct'
'coct'
'aoct'
'toct'
'eoct'
'lcct'
'occt'
'ccct'
'acct'
'tcct'
'ecct'
'lact'
'oact'
'cact'
'aact'
'tact'
'eact'
'ltct'
'otct'
'ctct'
'atct'
'ttct'
'etct'
'lect'
'oect'
'cect'
'aect'
'tect'
'eect'
'llat'
'olat'
'clat'
'alat'
'tlat'
'elat'
'loat'
'ooat'
'coat'
'aoat'
'toat'
'eoat'
'lcat'
'ocat'
'ccat'
'acat'
'tcat'
'ecat'
'laat'
'oaat'
'caat'
'aaat'
'taat'
'eaat'
'ltat'
'otat'
'ctat'
'atat'
'ttat'
'etat'
'leat'
'oeat'
'ceat'
'aeat'
'teat'
'eeat'
'lltt'
'oltt'
'cltt'
'altt'
'tltt'
'eltt'
'lott'
'oott'
'cott'
'aott'
'tott'
'eott'
'lctt'
'octt'
'cctt'
'actt'
'tctt'
'ectt'
'latt'
'oatt'
'catt'
'aatt'
'tatt'
'eatt'
'lttt'
'ottt'
'cttt'
'attt'
'tttt'
'ettt'
'lett'
'oett'
'cett'
'aett'
'tett'
'eett'
'llet'
'olet'
'clet'
'alet'
'tlet'
'elet'
'loet'
'ooet'
'coet'
'aoet'
'toet'
'eoet'
'lcet'
'ocet'
'ccet'
'acet'
'tcet'
'ecet'
'laet'
'oaet'
'caet'
'aaet'
'taet'
'eaet'
'ltet'
'otet'
'ctet'
'atet'
'ttet'
'etet'
'leet'
'oeet'
'ceet'
'aeet'
'teet'
'eeet'
'llle'
'olle'
'clle'
'alle'
'tlle'
'elle'
'lole'
'oole'
'cole'
'aole'
'tole'
'eole'
'lcle'
'ocle'
'ccle'
'acle'
'tcle'
'ecle'
'lale'
'oale'
'cale'
'aale'
'tale'
'eale'
'ltle'
'otle'
'ctle'
'atle'
'ttle'
'etle'
'lele'
'oele'
'cele'
'aele'
'tele'
'eele'
'lloe'
'oloe'
'cloe'
'aloe'
'tloe'
'eloe'
'looe'
'oooe'
'cooe'
'aooe'
'tooe'
'eooe'
'lcoe'
'ocoe'
'ccoe'
'acoe'
'tcoe'
'ecoe'
'laoe'
'oaoe'
'caoe'
'aaoe'
'taoe'
'eaoe'
'ltoe'
'otoe'
'ctoe'
'atoe'
'ttoe'
'etoe'
'leoe'
'oeoe'
'ceoe'
'aeoe'
'teoe'
'eeoe'
'llce'
'olce'
'clce'
'alce'
'tlce'
'elce'
'loce'
'ooce'
'coce'
'aoce'
'toce'
'eoce'
'lcce'
'occe'
'ccce'
'acce'
'tcce'
'ecce'
'lace'
'oace'
'cace'
'aace'
'tace'
'eace'
'ltce'
'otce'
'ctce'
'atce'
'ttce'
'etce'
'lece'
'oece'
'cece'
'aece'
'tece'
'eece'
'llae'
'olae'
'clae'
'alae'
'tlae'
'elae'
'loae'
'ooae'
'coae'
'aoae'
'toae'
'eoae'
'lcae'
'ocae'
'ccae'
'acae'
'tcae'
'ecae'
'laae'
'oaae'
'caae'
'aaae'
'taae'
'eaae'
'ltae'
'otae'
'ctae'
'atae'
'ttae'
'etae'
'leae'
'oeae'
'ceae'
'aeae'
'teae'
'eeae'
'llte'
'olte'
'clte'
'alte'
'tlte'
'elte'
'lote'
'oote'
'cote'
'aote'
'tote'
'eote'
'lcte'
'octe'
'ccte'
'acte'
'tcte'
'ecte'
'late'
'oate'
'cate'
'aate'
'tate'
'eate'
'ltte'
'otte'
'ctte'
'atte'
'ttte'
'ette'
'lete'
'oete'
'cete'
'aete'
'tete'
'eete'
'llee'
'olee'
'clee'
'alee'
'tlee'
'elee'
'loee'
'ooee'
'coee'
'aoee'
'toee'
'eoee'
'lcee'
'ocee'
'ccee'
'acee'
'tcee'
'ecee'
'laee'
'oaee'
'caee'
'aaee'
'taee'
'eaee'
'ltee'
'otee'
'ctee'
'atee'
'ttee'
'etee'
'leee'
'oeee'
'ceee'
'aeee'
'teee'
'eeee'
s2=sum(prod(prob(idx2),2))
s2 = 1.0000
David Hill
2022년 10월 29일
Even better
x='locate';prob=[.1 .18 .02 .4 .08 .22];
order=3;
b=cell(1,order);
[b{:}] = ndgrid(1:length(x));
idx=[];
for k=1:length(b)
idx=[idx,b{k}(:)];
end
X=x(idx)
X = 216×3 char array
'lll'
'oll'
'cll'
'all'
'tll'
'ell'
'lol'
'ool'
'col'
'aol'
'tol'
'eol'
'lcl'
'ocl'
'ccl'
'acl'
'tcl'
'ecl'
'lal'
'oal'
'cal'
'aal'
'tal'
'eal'
'ltl'
'otl'
'ctl'
'atl'
'ttl'
'etl'
'lel'
'oel'
'cel'
'ael'
'tel'
'eel'
'llo'
'olo'
'clo'
'alo'
'tlo'
'elo'
'loo'
'ooo'
'coo'
'aoo'
'too'
'eoo'
'lco'
'oco'
'cco'
'aco'
'tco'
'eco'
'lao'
'oao'
'cao'
'aao'
'tao'
'eao'
'lto'
'oto'
'cto'
'ato'
'tto'
'eto'
'leo'
'oeo'
'ceo'
'aeo'
'teo'
'eeo'
'llc'
'olc'
'clc'
'alc'
'tlc'
'elc'
'loc'
'ooc'
'coc'
'aoc'
'toc'
'eoc'
'lcc'
'occ'
'ccc'
'acc'
'tcc'
'ecc'
'lac'
'oac'
'cac'
'aac'
'tac'
'eac'
'ltc'
'otc'
'ctc'
'atc'
'ttc'
'etc'
'lec'
'oec'
'cec'
'aec'
'tec'
'eec'
'lla'
'ola'
'cla'
'ala'
'tla'
'ela'
'loa'
'ooa'
'coa'
'aoa'
'toa'
'eoa'
'lca'
'oca'
'cca'
'aca'
'tca'
'eca'
'laa'
'oaa'
'caa'
'aaa'
'taa'
'eaa'
'lta'
'ota'
'cta'
'ata'
'tta'
'eta'
'lea'
'oea'
'cea'
'aea'
'tea'
'eea'
'llt'
'olt'
'clt'
'alt'
'tlt'
'elt'
'lot'
'oot'
'cot'
'aot'
'tot'
'eot'
'lct'
'oct'
'cct'
'act'
'tct'
'ect'
'lat'
'oat'
'cat'
'aat'
'tat'
'eat'
'ltt'
'ott'
'ctt'
'att'
'ttt'
'ett'
'let'
'oet'
'cet'
'aet'
'tet'
'eet'
'lle'
'ole'
'cle'
'ale'
'tle'
'ele'
'loe'
'ooe'
'coe'
'aoe'
'toe'
'eoe'
'lce'
'oce'
'cce'
'ace'
'tce'
'ece'
'lae'
'oae'
'cae'
'aae'
'tae'
'eae'
'lte'
'ote'
'cte'
'ate'
'tte'
'ete'
'lee'
'oee'
'cee'
'aee'
'tee'
'eee'
p=prod(prob(idx),2)
p = 216×1
0.0010
0.0018
0.0002
0.0040
0.0008
0.0022
0.0018
0.0032
0.0004
0.0072
Ben Nguyen
2022년 11월 2일
David, you are a gods-sent. Based on your code (the first one without the for loop since I understood it better), I improvised my own. It worked. Thank you so much!!!
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)