Interview qustion matlab function

조회 수: 2 (최근 30일)
Mohammed kandeel
Mohammed kandeel 2018년 6월 29일
댓글: Mohammed kandeel 2018년 7월 14일
I asked to implement function it's input is a vector and plot it with time.
ex: lets suppose the input vector is [ 0 1 2 3 3 3 4 4 4 4 4 5 5 5 6 7 8]
if you can see there are 17 element so the time vector will be from [1......17]
but back to the input vector and take these values [0 1 2 3] can be represent from [1 3]
but time must be still [1 2 3 4], so when the slop is equal i need to keep first and last one and delete the middle elements.
back to input vector again i will see this [3 3 3] can be represent from [3 3]
but time must be still [3 4 5], so here will be constant line.
and so one the next input [4 4 4 4 4] equal to [4 4] with time from [6 7 8 9 10], Linear constant
so you need to generate new vector but the shape of it equal to the original shape.
Thanks in advance.
  댓글 수: 7
Guillaume
Guillaume 2018년 6월 29일
a = [1 2 2 2 2 3 4 5 6 7 7 7 7 8]
idx = [1, find(diff(diff(a)))+1, numel(a)]
plot(idx, a(idx));
David Goodmanson
David Goodmanson 2018년 6월 29일
yes, I forgot that (in this case) points 3 thru 6 are not included.

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

답변 (1개)

Mohammed kandeel
Mohammed kandeel 2018년 7월 9일
Hello Guillaume,
I just want to ask how many years of experience you take to get this solution?
i just used matlab less than one year. i can't answer this question within 2 minutes.
  댓글 수: 3
Guillaume
Guillaume 2018년 7월 9일
Yes, the hardest part is working out what the question is! Once that is understood, the problem reduces to finding the changes of slope in the data which is trivial to do in matlab. It doesn't take years of experience to understand that diff(X) is the slope, and diff(diff(X)) is the change of slope (2nd derivative).
Note: a good way to practice with similar problems is Cody
Mohammed kandeel
Mohammed kandeel 2018년 7월 14일
Thanks for all of you, i really love to ask to understand to share knowledge.
Love you all and "Guillaume" i will start with link you provide me.
One more Question What is the best book to start with Matlab script , simulink and stateflow ?

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

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by