Need the row of an array that gives minimum value if we sum all the elements of the row in a matrix?
2 views (last 30 days)
Show older comments
clear all
clc
% S(j)= sum of sub illuminance induced by each luminaire (illuminance produced on jth location)
% m = number of luminaires
% n = number of preferred illuminance
% li(j)= largest illuminance of jth location induced only by ith luminaire i = no of luminaires, j = locations )
% Let us consider L matrix
L= [90 106 25 51 56 19 18 18 11 7 9 7;
20 91 114 17 51 59 11 18 20 6 9 9;
9 37 158 8 27 75 6 8 23 5 8 9;
79 35 9 133 42 8 47 23 6 16 8 5;
8 28 80 8 30 127 5 18 46 5 7 8;
7 18 34 7 27 95 7 27 103 5 14 34;
11 15 17 14 32 36 17 74 91 16 58 65;
6 12 18 7 19 43 7 29 124 7 28 38]
x=max(L(3,:))
% T=rand(1,12)
Llt=100;
Ult=350;
Se=Llt+(Ult-Llt).*rand(8,1)
res=[];
TT=[];
for i=1:10000
T(i,:)=rand(1,12);
end
for j=1:10000
Scc=L*T(j,:)';
b=Scc>=Se;
if b==ones(8,1)
TT=[TT;T(j,:)];
ff=j
end
end
A=size(TT)
mm=A(1)
nn=A(2)
for l=1:A(1)
s(l,:)=sum(TT(l,:));
end
xx=min(s)
% Need the row of 'TT' that gives minimum of 's'
5 Comments
Guillaume
on 7 Nov 2018
Edited: Guillaume
on 7 Nov 2018
I'm not sure why the code is relevant to the question. I've not tried to understand as it looks more complicated than it needs. First things, I've spotted:
for i=1:10000
T(i,:)=rand(1,12);
end
is simply
T = rand(10000, 12);
and
A=size(TT)
for l=1:A(1)
s(l,:)=sum(TT(l,:));
end
is simply
s = sum(TT, 2);
and
b=Scc>=Se;
if b==ones(8,1)
is simply
b=Scc>=Se;
if all(b)
Accepted Answer
madhan ravi
on 7 Nov 2018
[~,xx]=min(s)
TT(xx,:) %row for minimum value of s
2 Comments
madhan ravi
on 8 Nov 2018
Anytime :) also consider Guillaume’s comment which makes your code really efficient
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!