Refer columns in data types of two different tables

조회 수: 1 (최근 30일)
Damith
Damith 2015년 9월 1일
댓글: Damith 2015년 9월 2일
Hi,
I need to to access the 2nd column of each cell of "yearnflow". The code I tried below does not work. Can somebody help me to understand what I am doing wrong.? Basically, I need to find the maximum flow for each year.
for i=1:1:48
Qmax(i,1)=max(yearnflow{1,1}([RowID(i,2):RowID(i,3)],:));
end

답변 (1개)

Walter Roberson
Walter Roberson 2015년 9월 1일
편집: Walter Roberson 2015년 9월 2일
You are asking to extract all columns of multiple rows, so you are usually going to get out a something-by-2 matrix (since yearnflow{1,1} is 17532 x 2). You then ask for the max() of that. By default max() runs down the columns, so you would produce a 1 x 2 output, the max of each column. You then tried to store those two max values into a single location.
Corrected, with some minor optimization:
yf = yearnflow{1,1};
for R = 1:48
Qmax(R,:)=max(yf(RowID(R,2):RowID(R,3),:), 1);
end
This will produce Qmax as a 48 x 2 array.
If you want the max independent of the column, then you can use max(Qmax,2) after the above.
The ",1" on the max() is a good practice to account for the possibility that at some point only one row of data might be fetched from yearnflow. With only one row of data, it would look to MATLAB like a row vector instead of a pair of column vectors, so it would produce a single output instead of the expected 2. The ",1" tells MATLAB not to guess about which dimension to take the max() over, to always take the max() along the first dimension even if there is only one row.
  댓글 수: 3
Walter Roberson
Walter Roberson 2015년 9월 2일
You still have the problem that you have two columns in Flow but you are expecting to get a single value from the max(). Do you want the max independent of column, or do you want the max of one particular column, or do you want both max ?
Damith
Damith 2015년 9월 2일
Flow have only one column now.(I make it to one column see the image above). I want to have Qmax (either cell or double array) for each column in Flow matrix. Number of flow records (years) in each column in Flow is different and "nyears" show the numbers of years of flow records. "RowID" matrix 2 and 3 columns have the day references for starting ending years of each cell in Flow matrix.
Hope I made this clear. I have posted the code below but it give me an error.

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

카테고리

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