필터 지우기
필터 지우기

hi everyone , i need help to do this , thank u

조회 수: 2 (최근 30일)
mina massoud
mina massoud 2019년 4월 8일
댓글: mina massoud 2019년 4월 9일
clear all
clc
A=10*randn(1,8);
B=10*randn(1,8);
EA=A+2
EB=B+2
E=min(EA,EB)
% i need the value of A and B in a row vector that corrispond to the value of E
thank u

채택된 답변

Adam Danz
Adam Danz 2019년 4월 8일
편집: Adam Danz 2019년 4월 8일
The variable 'idx' tells you whether the minimum came from EA (idx=1) or EB (idx=2). Use that to pull out values from A and B as needed.
[E, idx] = min([EA;EB]); %only works if EA and EB are same size
% If you want one row vector of A and one for B
A0 = A(idx==1);
B0 = B(idx==2);
% If you want one row vector that combines A and B
AB = nan(1, length(E));
AB(idx==1) = A(idx==1);
AB(idx==2) = B(idx==2);
  댓글 수: 13
mina massoud
mina massoud 2019년 4월 9일
%this is the part of the code that doesn't work
for i=1:300
for j=1:100
A{i,j}=10*randn(2,8);
B{i,j}=10*randn(2,8);
MA{i,j}=mean(A{i,j},1);
MB{i,j}=mean(B{i,j},1);
[E{i,j}, idx{i,j}] = min([MA{i,j};MB{i,j}]);
AB{i,j} = nan(2, length(E{i,j}));
AB{i,j}(idx==1) = A{i,j}(idx==1 );
AB{i,j}(idx==2) = B{i,j}(idx==2);
end
end
% thank you adam
mina massoud
mina massoud 2019년 4월 9일
% i tried also this , but still not working
for i=1:300
for j=1:100
A{i,j}=10*randn(2,8);
B{i,j}=10*randn(2,8);
MA=mean(A{i,j},1);
MB=mean(B{i,j},1);
[E, idx] = min([MA;MB]);
AB = nan(2, length(E));
AB(idx==1) = A(:,idx==1);
AA{i,j}=AB
AB(idx==2) = B(:,idx==2);
AA{i,j}=AB
end
end

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by