Filter löschen
Filter löschen

Plot 2D streamline_issue

5 Ansichten (letzte 30 Tage)
MS
MS am 9 Mai 2020
Kommentiert: MS am 11 Mai 2020
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 Kommentar
Ameer Hamza
Ameer Hamza am 9 Mai 2020
variable Ug and Vg are also not defined in this code. Can you give the code with generates the figure in question?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 10 Mai 2020
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 Kommentare
MS
MS am 10 Mai 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 am 11 Mai 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');

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Vector Fields finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by