Hello, I need to convert a "n-by-2 column vector of [x y] pairs" into a "n-by-2 array of [x y] pairs". I did try the reshape and selector functions without any success, can someone help me?
In details : I use the findpath function to give me a number n of waypoints to go from a start point to a goal point, it returns a n-by-2 column vector. I need to link these points to a controllerPurePursuit block which takes a n-by-2 array as an input. When linked directly on Simulink, I get this error :
  • Expected waypoints to be an array with number of columns equal to 2.
Thank you very much

댓글 수: 8

Adam Danz
Adam Danz 2019년 12월 15일
편집: Adam Danz 2019년 12월 15일
"n-by-2 column" doesn't make sense. A column, by definition, is n-by-1. Are you describing an nx1 cell array where each element contains a 1x2 vector?
"array " is a generic term. There are cell arrays, matrices are arrays, there are structure arrays etc. Maybe you could give an explicit input/output example.
Bandar
Bandar 2019년 12월 15일
May be you need to elaborate a bit more. Array and vector are terms used interchangeably in Matlab.
Pierre FEHLEN
Pierre FEHLEN 2019년 12월 15일
The findpath function returns a vector such as :
path =
1.0000 1.0000
0.9481 0.9623
1.5254 1.6883
By array I think he takes matrices as input, although I'm not sure, what I do not understand is that path is a matrice [n;2] so it has two columns as required by the controllerPurePursuit, but it says that an array is expected.
Adam Danz
Adam Danz 2019년 12월 15일
path is already an nx2 array.
Pierre FEHLEN
Pierre FEHLEN 2019년 12월 15일
That's what I thought, but then why Simulink says :
  • Expected waypoints to be an array with number of columns equal to 2.
Adam Danz
Adam Danz 2019년 12월 15일
path does have 2 columns. Something's not adding up.
Maybe that's the problem. path is a very important globa variable and evidently you overwrote it with some variable of yours. That is likely to cause some problems. DON'T name your variables after built in variables or function names.
If x is a column vector that you already have, and y is a column vector and your other function needs an N-by-2 array of values where each row is a corresponding (x,y) pair, then you can simply create a new matrix called xy
xy = [x, y];
and pass that into your function.
Marco Soriano
Marco Soriano 2022년 5월 3일
Hi, did you ever solve the problem?

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

답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2019년 12월 15일

댓글:

2022년 5월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by