現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
Finding minimum value by using min()
3 ビュー (過去 30 日間)
古いコメントを表示
I want to find minimum 10 value
i wrote
for j= 1:10
for i= 1:10
for k = 1:13
fitness (j,i,k)=(........);%10*10*13 double
end
end
minfit(j) = min(fitness(j,:));
end
disp (minfit);
in min function it is unable to find
minimum value of .
please helpme i am not able to solfitnesse
採用された回答
Image Analyst
2018 年 12 月 7 日
To find the 10 minimum values of any array, just sort:
sortedValues = sort(fitness(:), 'descend');
tenMinValues = sortedValues(1:10);
If you don't want duplicated values, use unique
sortedValues = unique(fitness(:));
tenMinValues = sortedValues(1:10);
6 件のコメント
Sushree Patra
2018 年 12 月 7 日
Thank you sir Steven,
I need a source code for Free search krill herd algorithm for global optimization.
Can you help me sir?
Image Analyst
2018 年 12 月 7 日
How is that different than the numerous other animal herd/swarm/flock/etc. algorithms?
There is no Krill Toolbox so if you can't find it in the File Exchange, and can't use one of the other PSO (Particle Swarm Optimization) algorithms, then you could ask the author (whoever invented it) for code, or write it yourself from lower level functions.
Sushree Patra
2018 年 12 月 7 日
Thank you sir for the response.
Well, it is different in case of movement of krill and finding the next generation they specifically use free search operator and opposition based method for population intialization.
And I asked to the author but they don't reply.
So I am trying by myself.
Please help me if I am unable to solve.
Image Analyst
2018 年 12 月 7 日
I've done all the help I can do. See the FAQ
I'm not an expert in PSO-type algorithms, and haven't used them (not needed to so far).
その他の回答 (1 件)
madhan ravi
2018 年 12 月 7 日
編集済み: madhan ravi
2018 年 12 月 7 日
minFit=squeeze(min(Ofitness,[],[1 2])).'
minFit=squeeze(min(min(Ofitness))).' % in older versions of matlab thank you sir Walter
32 件のコメント
Sushree Patra
2018 年 12 月 7 日
showing error
error using min
Dimension argument must be a positive integer scalar within index range.
i placed min function outside of all theloop 3 for
Jan
2018 年 12 月 7 日
@Sushree Patra: Please post the code. It is strange, that you get two different errors. Without seeing the code, it is impossible to fix it.
Sushree Patra
2018 年 12 月 7 日
ok i post it
clc;
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 25;
figure;
imshow('pc3.png');
hold on
hold on
%legend('Relay', 'Sink', 'Sensor');
%
x1 = [105,107,58,58,75,146,118,18,48,55,108,80,80];
y1 = [190,280,190,280,145,153,103,153,103,65,65,50,10];
hold on
A=100;
B=140;
plot(A,B, 'mo-', 'MarkerSize', 10,'LineWidth', 2);
hold on
hold on
% Make 75 points in set #2
Xmin = 60;
Xmax = 99;
x2 = Xmin+rand(1,50)*(Xmax-Xmin);
Ymin = 10;
Ymax= 260;
y2 = Ymin+rand(1,50)*(Ymax-Ymin);
plot(x2, y2, 'b*');
%numPoints2 = 50;
%x2 = 167*rand(numPoints2, 1);
%y2 = 302*rand(numPoints2, 1);
% Plot set 1 in red
plot(x1, y1, 'r.', 'MarkerSize', 13);
% Plot set 2 in blue
hold on;
plot(x2, y2, 'b*', 'MarkerSize', 5);
grid on;
for i=1:13
for j=1:50
%Find distances between every point in set 1 to every point in set #2.
distances(i,j) = pdist2([x1(i),y1(i)], [x2(j), y2(j)], 'euclidean');
end
minDistance(i) = min(distances(i,:));
end
% Find min distance
disp (distances);
dist1 = sqrt((x2-A).^2+(y2-B).^2)
%disp (dist1);
dist2 =sqrt((x1-A).^2+(y1-B).^2)
disp (minDistance);
a=1:40;
for i = 1:10
pop(i,:) = a(randperm(numel(a),10))
end
for i = 1:10
opo_pop(i,:) = 41-pop(i,:)
end
%Est(13,5)=zeros();
%for i=1:13
% b=1;
%for k=1:50
%for j=10*k-9:10*k
%if mod(k,10)==0
%b=b+1;
%end
s=250;
Et=16.7;
Eamp=1.97;
N=10;
data_agg=1;
Er = 36.1;
d0=30;
c=10;
for k = 1:13
for j = 1:10
for i = 1:10
Ets(k,j,i)=s*(Et+Eamp*(distances(k,pop(j,i)).^2));
%Es(i,b)=Est(i,b)+Et(i,k);
end
end
end
disp (Ets);
for k = 1:13
for j = 1:10
for i = 1:10
OEts(k,j,i)=s*(Et+Eamp*(distances(k,opo_pop(j,i)).^2));
%Es(i,b)=Est(i,b)+Et(i,k);
end
end
end
disp (OEts);
%disp(Es);
for j=1:10
for i=1:10
for k= 1:1
Etf(j,i,k)= N*data_agg*Et*(s*dist1(k,pop(j,i)))+N*s*data_agg*Et;
Erf = (N-1)*Er*s;
%Ef_total(i,k)=Etf(i,k)+Erf
end
end
end
Ef_total =Etf + Erf
for j=1:10
for i=1:10
for k= 1:1
OEtf(j,i,k)= N*data_agg*Et*(s*dist1(k,opo_pop(j,i)))+N*s*data_agg*Et;
OErf = (N-1)*Er*s;
%Ef_total(i,k)=Etf(i,k)+Erf
end
end
end
OEf_total =OEtf + OErf
for j=1:10
for i =1:10
for k = 1:13
fitness(j,i,k)= (c*pop(j,i)*1)+(c*(Ets(k,j,i)*1+Ef_total(j,i,1)*1))+(c*sqrt((distances(k,pop(j,i))-d0).^2))+(c*1);
end
end
%minFit(j) = min(fitness(j,:,:));
end
minFit = min(fitness,[],[1,2]);
disp(fitness);
for j=1:10
for i =1:10
for k = 1:13
Ofitness(j,i,k)= (c*opo_pop(j,i)*1)+(c*(OEts(k,j,i)*1+OEf_total(j,i,1)*1))+(c*sqrt((distances(k,opo_pop(j,i))-d0).^2))+(c*1);
end
end
OminFit(j) = min(Ofitness(j,:));
end
disp(Ofitness);
disp(minFit);
minfit=minFit(:);
disp(OminFit);
ominfit=OminFit(:);
Int_Fit = [minfit;ominfit]
intfitness = sort(Int_Fit)

madhan ravi
2018 年 12 月 7 日
REmove this section of the code!:
for j=1:10
for i =1:10
for k = 1:13
Ofitness(j,i,k)= (c*opo_pop(j,i)*1)+(c*(OEts(k,j,i)*1+OEf_total(j,i,1)*1))+(c*sqrt((distances(k,opo_pop(j,i))-d0).^2))+(c*1);
end
end
OminFit(j) = min(Ofitness(j,:));
end
Sushree Patra
2018 年 12 月 7 日
Error using min
Dimension argument must be a positive integer scalar within indexing range.
Error in rly_sen (line 128)
minFit = min(fitness,[],[1,2]);
madhan ravi
2018 年 12 月 7 日
wierd this is what i got:
>> minFit
minFit(:,:,1) =
14831476.9829354
minFit(:,:,2) =
52886274.7233204
minFit(:,:,3) =
20688650.8562262
minFit(:,:,4) =
53651138.6228232
minFit(:,:,5) =
7829219.62925941
minFit(:,:,6) =
18287522.4496381
minFit(:,:,7) =
10960447.7077643
minFit(:,:,8) =
27724536.6404127
minFit(:,:,9) =
19579242.1922717
minFit(:,:,10) =
29888312.5238552
minFit(:,:,11) =
24860479.583199
minFit(:,:,12) =
31616660.2405204
minFit(:,:,13) =
47582942.7897235
>>
Sushree Patra
2018 年 12 月 7 日
if i am usin min function like this
minFit(j) = min(Ofitness(j,:));
then no error but it is not calculate the minimum value correctly
madhan ravi
2018 年 12 月 7 日
Ofitness is a 3D matrix , which minimum do you want to return? minimum of each row/column or the minimum of each page?
Sushree Patra
2018 年 12 月 7 日
first loop i.e j is for 10 set
second loop is for with in each set 10 value
thired loop is for 13 fixed node
i calculated the distance of each value with 13 fixed node of 10 set that is 10*10*13
now i have the find 10 minimum of all of the values and stored in minfit
Sushree Patra
2018 年 12 月 7 日
but it shows minimum value with respect to all the 13 node
is it possible to find only 10 minimum fitness value whhich is stortest among all
Sushree Patra
2018 年 12 月 7 日
Among all best 10 minimum might be calculate by sort them and choose first 10
madhan ravi
2018 年 12 月 7 日
編集済み: madhan ravi
2018 年 12 月 7 日
minFit=squeeze(min(Ofitness,[],[1 2])).' % after this I don't have any clue what you want
madhan ravi
2018 年 12 月 7 日
Thank you so much sir Walter , is there any alternatives for it in older versions?
Sushree Patra
2018 年 12 月 7 日
Thank you sir madhan, I apply the solution you gave but now minFit value equal to the fitness value
not find minimum of 10 set.
Let me clarify the objective
10 set
each set have 10 number
total number = 100
then that 100 connect to 13 then we find fitness and Ofitness
fitness & Ofitness = 10*10*13
now calculate only 10 minimum values of that 10 set means set 1 having 10*13 fitness we have to find the minimum among all. like wise for 10 set i.e. my 10 minimum
Sushree Patra
2018 年 12 月 7 日
Please help me sir, I am also trying but recently i started matlab so kindly help me to solve the problem.
Thank you very much for your solutions and time
madhan ravi
2018 年 12 月 7 日
forget about everything demonstrate a neat and clean example with 2 by 2 matrix with 2 pages with your desired result it'll save time and avoid confusions
Sushree Patra
2018 年 12 月 7 日
編集済み: Sushree Patra
2018 年 12 月 7 日
(,1)=
A=[1,5;6,2]
A'=[9,5;3,6]
(,2)=
B=[9,2;6,3]
B'=[7,3;8,4]
Now i have to find out 2 minimum value one from (,1)another from (,2)
min=[1,2]
madhan ravi
2018 年 12 月 7 日
A(:,:,1)=[1,5;6,2];
A(:,:,2)=[9,5;3,6];
B(:,:,1)=[9,2;6,3];
B(:,:,2)=[7,3;8,4];
result=[min(A(:)) min(B(:))]
参考
カテゴリ
Help Center および File Exchange で Problem-Based Optimization Setup についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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 (한국어)
