How can I produce a 3d graph in my code? (surf? mesh?)

1 Ansicht (letzte 30 Tage)
Alzapoa
Alzapoa am 2 Sep. 2012
Hi all. I have below code and it create me landa-Cp curves for a range of B. I need to create a 3D graph of xyz i.e. landa,B,Cp.
Could you help please?
you may change my code accordingly.
Thank you,
Cpmax=[ ];
Cp=[ ];
landa=(0:0.05:15);
B=[0 5 10 15 20 25];
for k=1:1:length(B)
for i=1:1:length(landa)
landa_i=1/((1/(landa(i)+0.08*B(k)))-(0.035/(B(k)^3+1)));
Cpi=0.22*((116/landa_i)-(0.4*B(k))-5)*exp(-12.5/landa_i);
Cp=[Cp Cpi];
end
Cpmax=[Cpmax max(Cp)];
plot(landa,Cp,'b');
% mesh(landa,B);
hold on;
Cp=[];
end
xlabel('Tip speed ratio (lambda)','fontsize',12);
ylabel ('Performance corfficient (Cp)','fontsize',12);
lineobj = findobj('type', 'line');
set(lineobj, 'linewidth', 2);
set(lineobj, 'linestyle', '-');
xlim([0 15]);
ylim([-0.05 0.59]);
hold off;

Antworten (2)

Image Analyst
Image Analyst am 2 Sep. 2012
Check out the waterfall() function.

Star Strider
Star Strider am 2 Sep. 2012
Bearbeitet: Star Strider am 2 Sep. 2012
I commented out (rather than deleted) the lines of code that either do not need to be included or that resulted in your not being able to produce a mesh plot. My example here may not be exactly what you want, but it will demonstrate how to create a matrix for a 3-D plot. I will leave it for you to follow what I did, since the changes were rather simple:
% Cpmax=[ ];
% Cp=[ ];
landa=(0:0.05:15);
B=[0 5 10 15 20 25];
for k1=1:1:length(B)
for k2=1:1:length(landa)
landa_i=1/((1/(landa(k2)+0.08*B(k1)))-(0.035/(B(k1)^3+1)));
Cpi=0.22*((116/landa_i)-(0.4*B(k1))-5)*exp(-12.5/landa_i);
% Cp=[Cp Cpi];
Cp(k1,k2) = Cpi;
end
% Cpmax=[Cpmax max(Cp)];
% plot(landa,Cp,'b');
% mesh(landa,B);
% hold on;
% Cp=[];
end
Cpmax = max(Cp, [], 2);
Cpmin = min(Cp, [], 2);
[Lx By] = meshgrid(landa, B);
figure(1)
meshc(Lx, By, Cp)
xlabel('Tip speed ratio (lambda)','fontsize',12);
ylabel ('Performance corfficient (Cp)','fontsize',12);
% lineobj = findobj('type', 'line'); set(lineobj, 'linewidth', 2);
% set(lineobj, 'linestyle', '-');
% xlim([0 15]);
% ylim([0 25]);
% zlim([-0.05 0.59]);
% hold off;
grid on
This code will also work for the waterfall plot ‘Image Analyst’ suggested. You can use the Cp matrix I created to experiment with it and with various other types of plots to see which ones best suit your needs.
Also please do not use ‘i’ or ‘j’ for loop indices. MATLAB uses these as its imaginary operators, and while they will work as loop indices, will definitely confuse calculations that involve complex numbers.

Kategorien

Mehr zu Graphics finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by