I need a help to plot 2D streamline along with the contour plot. I am unable to plot the steamline properly(startx,stary). I am attaching my plot in the figure. It is starting from the middle for some reason. kindly help me to solve it. I am attaching the data files for your refernce to test it.
navg = 11;
filenames = cell(navg,1);
for i = 1:navg
filenames = sprintf('queen2_test_%d.txt', i);
mydata{i}=importdata(filenames);
% writematrix(avg_mat{i}, filenames{i});
R = mydata{i}(:,1);%X
C = mydata{i}(:,2);%Y
U = mydata{i}(:,3);
V = mydata{i}(:,4);
F = mydata{i}(:,7)./5;%F(X,Y)
F(isnan(F)) = 0;
% F = max(F,0);
rg = linspace(0, max(R), 100);
cg = linspace(0, max(C), 100);
[Rg, Cg] = meshgrid(rg, cg);
Fg = griddata(R, C, F, Rg, Cg);
Ug = griddata(R, C, U, Rg, Cg);
Vg = griddata(R, C, V, Rg, Cg);
figure
ax = axes();
caxis([-5 5])
colorbar
ax.YDir = 'reverse';
% ax.Position(2) = ax.Position(2)+0.02;
hold on;
[CC,HH] = (contourf(Rg,Cg,Fg));
set(HH,'LineColor','none')
% contourf(peaks(20),10,'edgecolor','none');
colormap(bluewhitered);
ax.XAxisLocation = 'top';
% cb = colorbar('Location', 'south');
% cb.Position(2) = cb.Position(2)-0.11;
grid on;
hold on
xstart = linspace(.025, max(R),300);
ystart = .005*ones(size(xstart));
s = streamline(Rg,Cg,Ug,Vg,Rg,Cg,[0.1,10000]);
% s = streamline(Rg,Cg,Ug,Vg,xstart,ystart,[0.1,10000]);
% [s.Color] = deal('g');
quiver(R,C,U,V);
end

1 comentario

Ameer Hamza
Ameer Hamza el 9 de Mayo de 2020
variable Ug and Vg are also not defined in this code. Can you give the code with generates the figure in question?

Iniciar sesión para comentar.

 Respuesta aceptada

Ameer Hamza
Ameer Hamza el 10 de Mayo de 2020

0 votos

Try this code
navg = 11;
filenames = cell(navg,1);
for i = 1:navg
filenames = sprintf('queen2_test_%d.txt', i);
mydata{i}=importdata(filenames);
R = mydata{i}(:,1);%X
C = mydata{i}(:,2);%Y
U = mydata{i}(:,3);
V = mydata{i}(:,4);
F = mydata{i}(:,7)./5;%F(X,Y)
rg = linspace(0, max(R), 100);
cg = linspace(0, max(C), 100);
[Rg, Cg] = meshgrid(rg, cg);
Fg = griddata(R, C, F, Rg, Cg);
Ug = griddata(R, C, U, Rg, Cg);
Vg = griddata(R, C, V, Rg, Cg);
figure
ax = axes();
caxis([-5 5])
colorbar
ax.YDir = 'reverse';
hold on;
contourf(Rg,Cg,Fg);
colormap(bluewhitered);
ax.XAxisLocation = 'top';
grid on;
hold on
quiver(R,C,U,V)
%%%%% streamline plot section start
xstart = linspace(0, max(R), 50);
ystart = 0.004*ones(size(xstart));
s = streamline(Rg,Cg,Ug,Vg,xstart,ystart);
%%%%% streamline plot section end
axis([0.02 0.07 .01 0.1])
set(gca,'XTick',0.02:.02:.07)
set(gca,'XTickLabel',0.2:0.2:.7)
set(gca,'YTick',0:.02:.1)
set(gca,'YTickLabel',0:0.2:1)
xlabel('x/c')
ylabel('y/c')
h = colorbar;
pos = get(h,'Position');
h.Label.Rotation = 0;% to rotate the text
h.Label.Interpreter = 'latex';
h.Label.String = '$\ C_{p}$';
set(gca, 'Color', 'black');
%saveas(gcf,filenames(1:end-4),'png');
exportgraphics(gcf,[filenames(1:end-4),'.png'], 'Resolution', 600);
delete(gcf);
end

6 comentarios

MS
MS el 10 de Mayo de 2020
Editada: MS el 10 de Mayo de 2020
Thank you very much. I need few request in the plot. I could see only part of the stream line comapred to the quiver arrows as shown in the attached figure. Kindly let me know the possibility to change the colur and show arrow marks in the stream line.
Also, I need a consistent black colur line around the plot. Please let me know if you know the solution for it.
Ameer Hamza
Ameer Hamza el 10 de Mayo de 2020
I couldn't find a way to overlap the streamline and the quiver arrow.
To change the colors of quiver arrow, you can do something like this
q = quiver(R,C,U,V, 'Color', 'r');
and for streamlines, you can change color like this
s = streamline(Rg,Cg,Ug,Vg,xstart,ystart);
[s.Color] = deal('r');
To create black like around the axes, you can try to run
box on
after creating the axes.
MS
MS el 10 de Mayo de 2020
Thank you. Kindly let me know how to export as a mat lab figure(.fig) in the above code.
exportgraphics(gcf,[filenames(1:end-4),'.fig'], 'Resolution', 600);%not working for me
I am trying to fill the stream line by follwing method as of now. It is helping bit but not completely.
xstart = linspace(0, max(R), 500);% incresing the values
ystart = 0.005*ones(size(xstart));
s = streamline(Rg,Cg,Ug,Vg,xstart,ystart,[0.1,20000]);% incearing the last number in this line
Ameer Hamza
Ameer Hamza el 10 de Mayo de 2020
I am not sure about filling the streamlines. I haven't used this function quite often.
MS
MS el 10 de Mayo de 2020
Thank you ameer. I am able to save the .fig files using the follwing command line as you suggested.
savefig([filenames(1:end-4),'.fig']);
I will update a command line if i am able to make any progress about the stream line.
MS
MS el 11 de Mayo de 2020
I tried to increase the numbers. Still, i get the same issue here.
xstart = linspace(0, max(R), 1000);
ystart = 0.005*ones(size(xstart));
s = streamline(Rg,Cg,Ug,Vg,xstart,ystart);
[s.Color] = deal('g');

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Vector Fields en Centro de ayuda y File Exchange.

Preguntada:

MS
el 9 de Mayo de 2020

Comentada:

MS
el 11 de Mayo de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by