How to specify which output will be recorded from a for loop?
1 回表示 (過去 30 日間)
古いコメントを表示
I'm working on the following piece of code:
for i = 1:length(k);
for j = length(trials);
V1 = trials(j,1) / (1 + ([k,i] * 0));
V2 = trials(j,2) / (1 + ([k,i] * trials(j,3)));
P2 = 1 / (1 + exp(-B*(V2-V1)));
end
end
length of k is 100 and length of trials is 1330.
I want the three equations to each run for the first value of k, then the second, third etc., looping for the length of k.
I want this/these loop(s) to output a 1330 x 100 matrix (trials x k), with the matrix containing only the values from the equation P2.
The loop is currently outputting three variables, each with 101 values.
How would I get this to output as above?
0 件のコメント
回答 (1 件)
Mischa Kim
2017 年 10 月 23 日
編集済み: Mischa Kim
2017 年 10 月 23 日
Louisa, how about
P2(j,i) = 1 / (1 + exp(-B*(V2-V1)));
Careful with var names, though. i,j are also used as the imaginary unit in MATLAB. Just to be on the safe say I recommend to replace all i and j in your code by ii and jj.
for ii = 1:length(k);
for jj = length(trials);
V1 = trials(jj,1) / (1 + ([k,ii] * 0));
V2 = trials(jj,2) / (1 + ([k,ii] * trials(jj,3)));
P2(jj,ii) = 1 / (1 + exp(-B*(V2-V1)));
end
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!