Plot 2D streamline_issue
조회 수: 3 (최근 30일)
이전 댓글 표시
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/292015/image.png)
댓글 수: 1
Ameer Hamza
2020년 5월 9일
variable Ug and Vg are also not defined in this code. Can you give the code with generates the figure in question?
채택된 답변
Ameer Hamza
2020년 5월 10일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Vector Fields에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!