maximum value array of multiple arrays

조회 수: 84 (최근 30일)
William White
William White 2018년 7월 29일
편집: Stephen23 2018년 7월 29일
Suppose I have many arrays or vectors of data
A, B, C ....etc
I can create an array which has the maximum and minimum values using the max min function when I compare two arrays:
A = [1 2 3];
B = [3 2 1];
maximum = max(A,B)
minimum = min(A,B)
But for a third, fourth fifth array, this does not seem to work:
A = [1 2 3];
B = [3 2 1];
C = [2 3 2];
maximum = max(A,B,C)
minimum = min(A,B,C)
I am looking for a simple method to create an array of maximum and minimum values for many input arrays - I guess I am missing something obvious? I am working with many arrays (many hundreds) which each contain tens of thousands of data points. I can write a loop which finds the maximum of A&B and C&D then finds the maximum of AB and CD; then the maximum of ABCD and EFGH... and so on; but this seems labourious.
thanks in advance.
  댓글 수: 1
Stephen23
Stephen23 2018년 7월 29일
" I am working with many arrays (many hundreds) which each contain tens of thousands of data points."
Having lots of individual variables that you now want to process together is a sign that they should be stored in one variable. Putting the data into one variable makes the solution to your original question a trivial one-line operation, and hugely simplifies any other processing of the data.
"I can write a loop which finds the maximum of A&B and C&D then finds the maximum of AB and CD; then the maximum of ABCD and EFGH... and so on; but this seems labourious."
A loop is not so bad. Just make sure to avoid dynamically accessing the variable names!:

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

채택된 답변

Stephen23
Stephen23 2018년 7월 29일
편집: Stephen23 2018년 7월 29일
Put the data into one array and use the third dim argument:
arr = cat(3,A,B,C,...)
min(arr,[],3)
max(arr,[],3)
If arr is too large to fit into your computer's memory, then either:
  • use a loop,
  • concatenate subsets of the arrays at a time, using min / max with the dim argument each time.

추가 답변 (0개)

카테고리

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

제품


릴리스

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by