Incrementing rows and columns through looping
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Adam
am 13 Okt. 2016
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.
Antworten (1)
KSSV
am 13 Okt. 2016
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 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!