I am writing a for loop. like this,
%
stations=[1 1 1 2 2 2 3 3 3];
stats=[1 2 3];
datapb=[];
for i=1:length(station(s))
[row,col]=find(stations(i)==stats(1));
dataps=max(datap(row));
datapb=[datapb;dataps];
end
[DEPTH, ia3, ic3] = unique(datapb,'stable');
%
I would like to obtain three DEPTH by change the stats from stats(1) to stats(3). How could I use two for loop to finish the calculation? Thank you very much in advance!

댓글 수: 2

Krithika A
Krithika A 2018년 7월 24일
I don't understand what you are trying to do. Can you elaborate on your aim?
Pingyang Li
Pingyang Li 2018년 7월 24일
When the stations = 1, there will be three depths, such as 100 m, 400 m and 660 m. I would like to find out the maximum. Similar to stations = 2 or 3. And then put all the three depth together in the original sequence. Could you understand this?

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

 채택된 답변

Bob Thompson
Bob Thompson 2018년 7월 24일

0 개 추천

First thing:
[row,col]=find(stations(i)==stats(1));
This only looks at a single value of stations, so it can only return a single value for row and col. This means that dataps=max(datap(row)); will return every value as max, because it is only comparing one value at a time.
Also, stations is a 1x9 array, so all row values will be 1.
You might try something more like this to get your logic and max values.
for k = 1:length(stats);
dataps = max(datap(stations==stats(k)));
datapb=[datapb;dataps];
end

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2018년 7월 24일

댓글:

2018년 7월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by