Creating an associated value for an array based upon its position in another matrix

조회 수: 1 (최근 30일)
What I am trying to do is associate the y1 value with an SSP(:,2) value depending upon its relationship to SSP(:,1) 's depth.
y1i = 0:-1:-200 ; %a list of depths
SSP(:,1) = 0:-5:-200 ; %is a list of depths, referred to 'depths' below.
depths = SSP(:,1) ;
SSP(:,2) = linspace(1500,1480,41) ; %is a list of speeds, reffered to 'c' below.
c = SSP(:,2) ;
j = numel(depths) ;
k = numel(y1i) ;
for m = 1:k ;
for n = 1:(j-1) ;
y1i(m) <= depths(n) & y1i(m) > depths(n+1) ;
c1(m) = c(n) ;
end
end
I will be grateful for any advice that is given.
Thank you

채택된 답변

Raunak Gupta
Raunak Gupta 2019년 12월 6일
Hi,
I think the command below should be a conditional statement something like if .
y1i(m) <= depths(n) & y1i(m) > depths(n+1) ;
Also, I see c1 in the code is not initialized. Since it is changing size every iteration if it is not declared. Although this is not the error you might be facing but it is good practice to initialize the array beforehand.
  댓글 수: 1
William Dickie
William Dickie 2019년 12월 9일
Hi, you are right, it needed the 'if' command.
I also, had to separate the <= for some reason, it kept registering as an error.
Thank you for your assistance.

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

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by