error size regarding contour plot
조회 수: 5 (최근 30일)
이전 댓글 표시
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
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)
채택된 답변
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);
figure(2),
contour(xq,yq,zq,'ShowText','on')
grid on
colorbar('vert')
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

