Incrementing rows and columns through looping
9 ビュー (過去 30 日間)
古いコメントを表示
Hello
I'm using a for Loop to determine the closest values for a given Array and store the results in a matrix. The dimensions of the given arrays are A[2001x81] and B[733x1]. The command looks like this
for p = 1:size(A,2)
for q = 2:size(B,1)
count = count + 1;
aa1(:,count) = max(A(A(:,p)<B(q,:)));
end
end
When I excute the Loop, the values are stored in a single vector [1x59373]. How do I execute the Loop to store the values for each row and column in the same Matrix which should be {733x81] in the end? Thanks in advance.
1 件のコメント
Adam
2016 年 10 月 13 日
aa1(:,count) = max(A(A(:,p)<B(q,:)))';
probably works though I don't have your data to test it on. I imagine there are also ways to do this without a nested for loop, but I don't have time to consider them at the moment.
回答 (1 件)
KSSV
2016 年 10 月 13 日
A = rand(2001,81) ;
B = rand(733,1) ;
count = 0 ;
aa1 = zeros(81,733) ;
for p = 1:size(A,2)
for q = 2:size(B,1)
temp = max(A(A(:,p)<B(q)));
if ~isempty(temp)
aa1(p,q) = temp ;
else
aa1(p,q) = NaN ;
end
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!