error size regarding contour plot

10 ビュー (過去 30 日間)
Hossein
Hossein 2024 年 1 月 31 日
回答済み: Mathieu NOE 2024 年 1 月 31 日
I wan to plot a contour by using this code:
fileName = 'Simulation.txt';
nPitch = 202;
nTSR = 250;
%% Read in text file
fileID = fopen(fileName);
raw = textscan(fileID, '%f%f%f%f%f%f%f%f%f%f', 'Headerlines', 7);
fclose(fileID);
pitch = raw{3};
TSR = raw{7};
Cp = raw{8};
Ct = raw{8};
%% Re-arrange data
pitch = pitch(1:nPitch); % use individual values only
TSR = TSR(1:nPitch:end); % use individual values only
Cp = reshape(Cp, nPitch, nTSR, 1); % transform vector into matrix
Ct = reshape(Ct, nPitch, nTSR, 1); % transform vector into matrix
disp(pitch)
It seems number of unique value of pitch and TSR is wrong and this error appears:
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. Error in pitch_tsr_cp (line 23) Cp = reshape(Cp, nPitch, nTSR, 1); % transform vector into matrix
as I checked file also in excel I have 250 uniqe TSR value amd 202 pitch uniqe value.
  2 件のコメント
Mathieu NOE
Mathieu NOE 2024 年 1 月 31 日
hello
it would help if you could share the data file as well
maybe you need to zip it if it's too big (limit = 5 Mb)
Hossein
Hossein 2024 年 1 月 31 日
thank you so much for your answer, here is the main file

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

採用された回答

Mathieu NOE
Mathieu NOE 2024 年 1 月 31 日
hello
I believe this is what you wanted to do
I don't see why you needed the reshape action
unzip('Simulation.zip');
fileName = 'Simulation.txt';
% WIND [m/s] ROT [rpm] PITCH [deg] POWER [kW] THRUST [N] TORQUE [Nm] TSR [-] CP [-] CT [-] CM [-]
% Read in text file
data = readmatrix(fileName);
pitch = (data(:,3));
TSR = (data(:,7));
Cp = (data(:,8));
Ct = (data(:,9));
figure(1),
scatter3(TSR,pitch,Cp,10,Cp,'filled')
% Interpolate the scattered data on the grid. Plot the results.
N = 100;
xd = linspace(min(TSR),max(TSR),N);
yd = linspace(min(pitch),max(pitch),N);
[xq,yq] = meshgrid(xd,yd);
zq = griddata(TSR,pitch,Cp,xq,yq);
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
figure(2),
contour(xq,yq,zq,'ShowText','on')
grid on
colorbar('vert')

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by