필터 지우기
필터 지우기

comparision of data with logic given as input

조회 수: 1 (최근 30일)
Sumanth
Sumanth 2023년 2월 27일
편집: Walter Roberson 2023년 2월 28일
This is a sample data for 3. I am stuck at how to write the same logic for 10 such that there should be comparision for all the input values given for T1 ,T2, .... T10.
I = zeros(1,3);
if T1 == T2
I(1,1)= 1;
I(1,1)= 0;
elseif T1 > T2
I(1,1)= 1;
I(1,2)= 0;
elseif T1 < T2
I(1,1)= 0;
I(1,2)= 1;
end
note: only one element in I should be equal to 1 in the end in such a way that the highest T gets the value 1 in I.

채택된 답변

Voss
Voss 2023년 2월 27일
편집: Voss 2023년 2월 27일
Assuming T1, ..., T10 are scalars,
T = [T1 T2 T3 T4 T5 T6 T7 T8 T9 T10];
[~,idx] = max(T);
I = zeros(size(T));
I(idx) = 1;
  댓글 수: 2
Sumanth
Sumanth 2023년 2월 28일
Thank you so much! This works!
Voss
Voss 2023년 2월 28일
You're welcome!

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

추가 답변 (1개)

Steven Lord
Steven Lord 2023년 2월 27일
Can you dynamically create and operate on variables with numbered names like T1, T2, T3, etc.? Yes.
Should you do this? The general consensus is no. That Answers post explains why this is generally discouraged and offers several alternative approaches.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by