Convert vector to array
Show older comments
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 Comments
"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
on 15 Dec 2019
May be you need to elaborate a bit more. Array and vector are terms used interchangeably in Matlab.
Pierre FEHLEN
on 15 Dec 2019
Adam Danz
on 15 Dec 2019
path is already an nx2 array.
Pierre FEHLEN
on 15 Dec 2019
Adam Danz
on 15 Dec 2019
path does have 2 columns. Something's not adding up.
Image Analyst
on 15 Dec 2019
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
on 3 May 2022
Hi, did you ever solve the problem?
Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!