필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Store some data from one variable to another variable according to a condition

조회 수: 1 (최근 30일)
Angela Marino
Angela Marino 2020년 7월 1일
마감: MATLAB Answer Bot 2021년 8월 20일
Hi everyone, I have a little problem.
I have defined these two variables
vel(i,j) (exemple vel=[1 2 3 0 0 0 0 2 1 3 etc])
dist(i,j)
%i,j>>27
pos=ones(27,1)
I would like to store the given "dist" (i,1) corresponding "vel" == 0 only for the first value ==0
if vel(i,1)==0 && vel(i-1,1)~=0
pos(:,1)=dist(i,1);
end
Is the code correct to have what I want?
  댓글 수: 4
MaryD
MaryD 2020년 7월 1일
This not looks like it's going to work as you want only first value.
[index]=find(vel(:,1)==0,'first');
pos(:,1)=dist(index,1);
Try something like this instead
dpb
dpb 2020년 7월 1일
I fixed indenting to be able to at least see where the loops start/end but no real idea what is trying to be done...
...
%I identify the position of stops R2 and update the array
if veloc(i,1)==0 & veloc(i-1,1)~=0
pos_fermateR2(:,1)==distanza(i,1);
end
end % loop j
is inside the inner loop on both i and j so there's the question of what you're looking for and what subscripts mean...guessing, it looks like maybe i is over some time step and j some data set...but that's purely guessing.
veloc(i,1) and veloc(i-1,1) are each only addressing a single element in an array; and it looks like the (i,j) position is being set inside the loop.
I'm guessing you really want to move this to be after the j loop completes and then look over the i vector of veloc(i,:)
If that were correct, use something like
ixstop=find(veloc(i,:)==0,1);
pos_fermateR2(i)==distanza(i,ixstop);
But, this is really guessing about what the code really does...

답변 (0개)

이 질문은 마감되었습니다.

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by