필터 지우기
필터 지우기

Compare Elements in 2 Arrays

조회 수: 1 (최근 30일)
Ben Whitby
Ben Whitby 2024년 2월 15일
편집: Matt J 2024년 2월 15일
Hi,
I have two 15 x 1 arrays.
Gen_Excess = [44;44;42;55;57;35;34;38;58;56;42;35;55;55;54];
Batt_Cap = [55;55;55;49;49;49;48;48;48;46;46;46;45;45;45];
I want to compare the elements in Gen_Excess to the corresponding array elements in Batt_Cap. If the element in Gen_Excess is less than the element in Batt_Cap I want it to remain the same; however, if the element in Gen_Excess is greater than the corresponding element in Batt_Cap I want to set it to the value in Batt_Capp. For example if we consider the first elements of each array, element (1,1). The value in Gen_Excess is 44, which is less than 55 so i want it to reamin as 44. However, If we consider element (15,1) the value in Batt_Cap is 54 and so I want to change that element to 45. Along the lines of:
Gen_Excess(Gen_Excess > 45) = 45;
I hope this makes sense. Any advice would be appreciated.

채택된 답변

Matt J
Matt J 2024년 2월 15일
편집: Matt J 2024년 2월 15일
Gen_Excess=min(Gen_Excess,Batt_cap);

추가 답변 (1개)

Steven Lord
Steven Lord 2024년 2월 15일
Use the min function.

카테고리

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

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by