MATLAB Answers

Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#">ここ</a>」をクリックしてください。


Error using reshape and permute

Macon Pharr さんによって質問されました 2019 年 3 月 29 日
最新アクティビティ Macon Pharr さんによって コメントされました 2019 年 3 月 29 日
I have reqwritten a script where I want to reshape data from an engine deck to use for for some colormaps. I am currently recieving this error "To RESHAPE the number of elements must not change." where i have specificed in the code. I am trying to reshape the data to a 17x11x11 array, but I cant figure out what is wrong.
The reshape function is currently structured as reshape((924x1),[11,11,17])
function [thrust,fuelflow,tsfc]=cf34(M,h,pc)
if nargin<3;error('You must specify 3 inputs (M,h,pc)');end
if ~all((size(h) == size(M)) & (size(pc) == size(M)));error('Input matrices M, h, and pc must all be the same size');end
deck=makedeck; %924x6 double
%get full factorial dimensions
dims=[numel(unique(deck(:,1))) numel(unique(deck(:,2))) numel(unique(deck(:,3)))]; %[17, 11, 11] 17 unique values for data in column 1, 11 unique values for column 2 and column 3
%make grid of unique points
[Mdata hdata pcdata]=ndgrid(unique(deck(:,1)),unique(deck(:,2)),unique(deck(:,3))); % creates a 17x11x11 double matrix
%where the code is erroring:
thrustdata=permute(reshape(deck(:,4),fliplr(dims)),[3 2 1]);
fuelflowdata=permute(reshape(deck(:,5),fliplr(dims)),[3 2 1]);
tsfcdata=permute(reshape(deck(:,6),fliplr(dims)),[3 2 1]);
>> thrustdata=permute(reshape(deck(:,4),[fliplr(dims)]),[3 2 1]);
Error using reshape
To RESHAPE the number of elements must not change.

  0 件のコメント

サインイン to comment.

1 件の回答

回答者: Kevin Phung
2019 年 3 月 29 日

a 17*11*11 matrix contains 2057 elements, you have 1800.

  1 件のコメント

Macon Pharr 2019 年 3 月 29 日
You’re right. I updated the size of the matrix after I had posted it, but the data points are still wildly different.
I’m going to have to do some interpolating to increase the length of the matrix to get the reshape to work.

サインイン to comment.

Translated by