Error using reshape and permute

3 次查看(过去 30 天)
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.

采纳的回答

Kevin Phung
Kevin Phung 2019-3-29
a 17*11*11 matrix contains 2057 elements, you have 1800.
  1 个评论
Macon Pharr
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by