Convert vector to array

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.
May be you need to elaborate a bit more. Array and vector are terms used interchangeably in Matlab.
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.
path is already an nx2 array.
That's what I thought, but then why Simulink says :
  • Expected waypoints to be an array with number of columns equal to 2.
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.
Hi, did you ever solve the problem?

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by