RESHAPE and GRESHAPE

Good morning,
I’m having problems with the RESHAPE.M file, because it seems to require a GRESHAPE.M file. Anyone know how can I get it?

Where did you get the first file?

Reshape.m from communications package.
The problem is that I’ve this kind of error:

error: reshape: can’t reshape 36x3 array to 34x3 array

this is a problem that Matlab, on the other side, does not give to me.

I try to install the communication package and it says that reshape needs greshape, but I’m not able to find it.

Reshape function is an official command of OCTAVE but it is also in the communications package that’s why. I found on the web that communications-1.0.11.tar.gz has the greshape.m file, I don’t know if this could be the correct approach to solve the problem. Matlab does not give me this problem.reshape.m (1.8 KB)

The communications package doesn’t contain a reshape function for me with Octave 6.3.0 on Windows:

>> pkg list communications
Package Name    | Version | Installation directory
----------------+---------+-----------------------
communications  |   1.2.3 | C:\Program Files (x86)\GNU Octave\Octave-6.3.0\mingw32\share\octave\packages\communications-1.2.3
>> which reshape
'reshape' is a built-in function from the file libinterp/corefcn/data.cc
>> pkg load communications
>> pkg list communications
Package Name    | Version | Installation directory
----------------+---------+-----------------------
communications *|   1.2.3 | C:\Program Files (x86)\GNU Octave\Octave-6.3.0\mingw32\share\octave\packages\communications-1.2.3
>> which reshape
'reshape' is a built-in function from the file libinterp/corefcn/data.cc

What does which reshape return for you before and after loading the communications package?

At the moment I have removed the package communications so I’ve the original Octave Reshape. The error I’ve it is:

error: reshape: can’t reshape 36x3 array to 34x3 array

This is an error that Matlab does not give me with the same code.

It’s hard to tell what is causing this error without knowing the code that you are running.

What I thought is “maybe” using the attached reshape.m plus the greshape.m file can solve the problem probably because different from the originale Octave Reshape function.
That’s why I’m asking if someone has the greshape.m file reshape.m (1.8 KB)

page1
page2
Anyone has this greshape.m file? I know that it was included in the package communications.1.0.11.tar.gz

I think the problem will be solved using the old approach.

The mentioned function @galois/reshape.m is a member function of a class @galois and is not intended to be called “directly”. Probably your current directory is inside this class directory? :thinking:

The greshape function is a binary C++ function installed with the communications package from gf.cc (line 285).

To solve your issue, restart Octave and change to a “safe” directory, e.g. “Downloads”. If you still get problems with reshape / greshape, please anwer @mmuetzel question and post the output of

pwd
which reshape

Consider that at the moment I have found 7 different reshape.m files.
I can force the use of a reshape.m file inspite of another.

The error that I’ve with the original version, withouth forcing is

error: reshape: can’t reshape 36x3 array to 34x3 array
error: called from
mkpp at line 91 column 12

I think another solution could be to force the using of a reshape.m file written in a different way. At the moment Matlab does not give me this problem and the code works perfectly. So what is the difference from Matlab reshape and Octave reshape?

I don’t think it is reshape that is the problem.
If the code is trying to reshape a 36x3 array into a 34x3 array, something went wrong before the point of error…

This is part of the code, I do not understand why in Matlab it works and why in Octave not!
It is a tool for calculation of airfoil geometry.

[dummy, i_upside] = min(A(:,1));

upside_original = A(1:i_upside,:);
downside_original = A(i_upside+1:end,:);

clear A

x_upside_ordinati = sort(upside_original(:,1),‘descend’);

if max(x_upside_ordinati - upside_original(:,1)) == 0

else
upside_original = flipud(upside_original);
end

x_downside_ordinati = sort(downside_original(:,1),‘ascend’);

if max(x_downside_ordinati - downside_original(:,1)) == 0

else
downside_original = flipud(downside_original);
end

x_finali = [upside_original(:,1); downside_original(:,1)];
y_finali = [upside_original(:,2); downside_original(:,2)];
upside_original_old = upside_original;
upside_original = flipud(upside_original_old);
[dummy, i_max] = max(upside_original(:,2));
[dummy, i_min] = min(downside_original(:,2));
x_upside = upside_original(i_max:end,1);
y_upside = upside_original(i_max:end,2);
x_LE = [upside_original(i_max-1:-1:2,1); downside_original(1:i_min,1)];
y_LE = [upside_original(i_max-1:-1:2,2); downside_original(1:i_min,2)];
x_downside = downside_original(i_min+1:end,1);
y_downside = downside_original(i_min+1:end,2);
x_inizio_sp_upside = 0.3upside_original(i_max,1);
x_inizio_sp_downside = 0.3
downside_original(i_min,1);
[dummy i_sp_upside] = min(abs(upside_original(:,1) - x_inizio_sp_upside));
[dummy i_sp_downside] = min(abs(downside_original(:,1) - x_inizio_sp_downside));
x_upside_sp = upside_original(i_sp_upside:end,1);
y_upside_sp = upside_original(i_sp_upside:end,2);
tol = 0.000001;
sp_upside = csaps(x_upside_sp,y_upside_sp,1-tol); % Smooth spline
x_eval_upside = linspace(min(x_upside_sp),max(x_upside_sp),n_upside)’;
y_eval_upside = ppval(sp_upside,x_eval_upside);
[dummy1,C,dummy2,dummy3]=unmkpp(sp_upside);
Cder1_upside=[3C(:,1) 2C(:,2) C(:,3)];
Cder2_upside=[6C(:,1) 2C(:,2)];
sp_upside_1 = mkpp(x_upside_sp,Cder1_upside);
sp_upside_2 = mkpp(x_upside_sp,Cder2_upside);

the error related to reshape appears when I enter in the mkpp function

In the hope that this helps: If you have access to Matlab, step through your code in Matlab and in Octave and figure out where they start to differ.

Good afternoon,
I will try to solve the problem and I will inform you. So are you sure that it is not a problem related to the reshape function, but something below. Are you sure?
Checking the reshape files, I found sometimes functions that have

function Y = reshape (Y,varargin)

May be should be this the problem? A reference to the same Y?

That’s because the error is: error: reshape: can’t reshape 36x3 array to 34x3 array

That error usually indicates user error. E.g:

>> a = [1 2 3; 4 5 6; 7 8 9]
a =
     1     2     3
     4     5     6
     7     8     9

>> reshape (a, [3 2]) 
error: reshape: can't reshape 3x3 array to 3x2 array

I’d guess that no version of reshape that would be able to reshape a 36x3 matrix into a 34x3 matrix.
So, yes: It looks like the error is somewhere else in the code.

it is still quite unclear how the greshape function (which is completely different in purpose and usage to the reshape function) is related to your problem. Especially because the code you posted does not contain a call to either greshape or reshape, so we cannot use it to try to deduce the problem.

there is nothing wrong with function Y = reshape (Y,varargin) that is simply the function definition indicating that it will return the same variable given to it. as it’s a reshape function, one can assume that the returned Y will just be a different shape than the input Y

I also notice that Matlab appears to not have a greshape function at all, in its core or communications toolbox. As such I’m not at all sure how you were able to run a script requiring greshape at all under Matlab, unless we’re misunderstanding what’s occurred here.

Since the greshape and reshape commands are not expected to be related or interchangeable, is it possible that there was a typo in one of those function calls?

[quote=“michele.fazio, post:16, topic:1698”]
error: reshape: can’t reshape 36x3 array to 34x3 array
[/

What I’m not able to understand is “why in Matlab it works and in Octave it says error: reshape: can’t reshape 36x3 array to 34x3 array”

Are you sure it isn’t a bug of Octave that needs to be solved? Considering what discussed before, do you suggest me to verify how I get C? I’m using in this text X in place of *

[dummy1,C,dummy2,dummy3]=unmkpp(sp_upside)

Cder1_upside=[3xC(:,1) 2xC(:,2) C(:,3)];
Cder2_upside=[6xC(:,1) 2xC(:,2)];

sp_upside_1 = mkpp(x_upside_sp,Cder1_upside);
sp_upside_2 = mkpp(x_upside_sp,Cder2_upside);

The reshape error appears when I use mkpp