필터 지우기
필터 지우기

Info

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

listlib::insertAt will not work in script

조회 수: 1 (최근 30일)
Ross Hanna
Ross Hanna 2017년 9월 10일
마감: MATLAB Answer Bot 2021년 8월 20일
Hi there. I am trying to add a zero at the top of my vector so i can minus one vector from the other. Stating the reason may help... I have to work out the displacement of a spring. I am using the equation F=k/x, however, the true equation i need is F=k/(x-y), with y being the displacement of the spring from the original position as it increases the force if it is at a different position. I have looked through lots of the answers on here in regard to adding an element to a vector and subtracting the difference between 2 elements in a vector however diff() was giving the wrong answer and i was also having problems with vector sizes not being equal. The code i have at the moment is attached. This is not a homework problem it is part of my dissertation. Also if anyone can see anything that would slow it down i would be grateful as all of my matlab is self taught. Many Thanks

답변 (1개)

Walter Roberson
Walter Roberson 2017년 9월 10일
listlib::insertAt is only for use in MuPAD.
  댓글 수: 2
Ross Hanna
Ross Hanna 2017년 9월 10일
Hi there. I worked out from the documentation that it was only for MuPAD. I guess i should have been clearer with my question. I have now updated it to say that what i would like to know is if there is an equivalent function for use in scripts, another way to code the same thing or if there is something in the maths/physics that i am missing/ made a mistake in. Sorry for the ambiguity.
Walter Roberson
Walter Roberson 2017년 9월 10일
You need to discuss more why you say that "diff was giving the wrong answer".
diff(x) for vector x is the equivalent of x(2:end)-x(1:end-1)
To put a 0 at the beginning of a vector use either
[0, TheVector]
or
[0; TheVector]
depending on whether it is a row or column vector.

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

Community Treasure Hunt

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

Start Hunting!

Translated by