How to adjust reshape

2 ビュー (過去 30 日間)
Cesar Cardenas
Cesar Cardenas 2023 年 5 月 3 日
コメント済み: Torsten 2023 年 5 月 3 日
Hello, I'm trying to run this code but I'm still errors with reshape, not siure how to fix it. Any help will be greatly appreciated. Thanks
% clear;
% clc;
nx=225;
ny=66;
nfields=9;
a=readmatrix('NACA0012_1E-4_225x66.XYZ_M=0.5_ALPHA_5.0_TURBULENT.dat','Headerlines',5)';
b=reshape(a(1:nx*ny*2),[nx,ny,2]);
x=b(:,:,1);
y=b(:,:,2);
%centroids (improve this by averaging the 4 corners)
xc=x(1:end-1,1:end-1)+diff(x(:,1:end-1))/2 +diff(x(1:end-1,:),[],2)/2;
yc=y(1:end-1,1:end-1)+diff(y(:,1:end-1))/2 +diff(y(1:end-1,:),[],2)/2;
b=reshape(a(nx*ny*2+1:end),[nx-1,ny-1,nfields]);%nine dependent variables
bSz = size(b)
Error using reshape
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size for that dimension.
%plot pressure
figure;surf(xc,yc,b(:,:,4));
view(2);shading flat;axis image;axis([-1,1,-1,1])
  2 件のコメント
Jon
Jon 2023 年 5 月 3 日
Matt J
Matt J 2023 年 5 月 3 日
Error using reshape. Number of elements must not change
Debugging requires examining input. Have you looked at the number of elements in a(nx*ny*2+1:end), as the error message suggests?

サインインしてコメントする。

回答 (1 件)

Torsten
Torsten 2023 年 5 月 3 日
移動済み: Torsten 2023 年 5 月 3 日
Tell us what you get when you evaluate
numel(a(nx*ny*2+1:end))
and if it equals
(nx-1)*(ny-1)*nfields
If not, you cannot use "reshape" because the number of elements of the source and the target array are different.
  4 件のコメント
Cesar Cardenas
Cesar Cardenas 2023 年 5 月 3 日
got it, how could I fix it?
Torsten
Torsten 2023 年 5 月 3 日
got it, how could I fix it?
Since we all don't know what you are doing in your code, I think you are the only person who could answer this.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by