cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Reshape function

0 Kudos

Reshape function

The function reshape(M, p, q) returns an array of size p x q, formed from elements of the array M by their consistent sample columns. If the number of array elements M is not equal to the product p * q, an error message - see the attach

PS

Matlab (Matrix Laboratory) has this function

8 Comments
StuartBruff
23-Emerald II

Valery Ochkov wrote:

The function reshape(M, p, q) returns an array of size p x q, formed from elements of the array M by their consistent sample columns. If the number of array elements M is not equal to the product p * q, an error message - see the attach

PS

Matlab (Matrix Laboratory) has this function

I think the reshape function should form part of a true multi-dimensional array capability (MDA), as I've posted many, many, many times previously on the Collab - which would be more in keeping with the exact capability of the Matlab reshape function or that of the majority of matrix languages (eg, Mathematica).

Stuart

MikeArmstrong
5-Regular Member

Valery,

That is a lovely, lovely function.

Right in the filling cabinet.

Mike

ValeryOchkov
24-Ruby IV

Mike Armstrong wrote:

Valery,

That is a lovely, lovely function.

Right in the filling cabinet.

Mike

Thanks!

See a video in attach!

MikeArmstrong
5-Regular Member

Thanks!

See a video in attach!

I like it. Well done Valery.

Mike

Ninetrees
1-Newbie

As a long-time software engineer, I can't help but mess w code when I see it...and I started with this one /just/ to move the ERROR block to the outer level because I opine that it's best to determine at the outer-most level whether the code about to run might cause a fault, and handle it before any real work is done...

then, well, one thing led to another, "and the next thing you know" 😉

...here is the result, including an off-the-cuff speed test...

~R~

Oh, and I forgot to pre-allocate the destination matrix...so here is an update...and I added it to the original, too...

~R~

...and thanks to Mike's speed test example...better numbers and easier than all that enable/disable evaluation stuff that I was doing...

~R~

MikeArmstrong
5-Regular Member

Nice work Richard, definately an improvement.

Slightly more complex speed test included.

Mike

StuartBruff
23-Emerald II

As part of my updating of my library of utility functions, I'm attempting to introduce a slight degree of commonality between my standard library and my multi-dimensional array (MDA) library as far as names and overall intent goes. One of the functions is reshape (used primarily in my MDA library). As usual, the behaviour of the functions is driven by experience and laziness, so my latest incarnation of the standard reshape function doesn't return an error if the reshaped array doesn't have the same number of elements as the original; if the new array is smaller than the original, reshape only takes (in column order) as many elements as it needs and discards the rest, if the new array is larger then reshape pads the end of the new array with NaNs.

The attached worksheet also includes one my standard timer functions to ease performance testing, plus an MDA reshape example.

Stuart

olivierlp
Community Manager
Status changed to: Archived

Hello,

We are archiving your idea as part of a general review. This action is based on the age of your idea and the total number of votes received, as per this announcement.

You can always post a new idea with all the details required in the form.

Thank you for your participation.