plot 2D contours

2 Ansichten (letzte 30 Tage)
MS
MS am 5 Mai 2020
Kommentiert: MS am 8 Mai 2020
I need help to plot 2D contours as shown in the figure for mutiple files. I am attaching my code and data files for your reference. I am unable to plot it due to some mistake in the code.
navg = 11;
filenames = cell(navg,1);
for i = 1:navg
filenames = sprintf('queen2_test_%d.dat', i);
mydata{i}=importdata(filenames);
% writematrix(avg_mat{i}, filenames{i});
R = mydata{i}(:,1);%X
C = mydata{i}(:,2);%Y
F = mydata{i}(:,7);%F(X,Y)
figure
contour(R,C,repmat(F,1,numel(C))');
grid on;
end
saveas(gcf,figure,'.png']);

Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 5 Mai 2020
Bearbeitet: Ameer Hamza am 5 Mai 2020
Run the attached code with the files you provided
navg = 11;
filenames = cell(navg,1);
for i = 1:navg
filenames = sprintf('queen2_test_%d.dat', i);
mydata{i}=importdata(filenames);
% writematrix(avg_mat{i}, filenames{i});
R = mydata{i}(:,1);%X
C = mydata{i}(:,2);%Y
F = mydata{i}(:,7);%F(X,Y)
rg = linspace(min(R), max(R), 100);
cg = linspace(min(C), max(C), 100);
[Rg, Cg] = meshgrid(rg, cg);
Fg = griddata(R, C, F, Rg, Cg);
figure
ax = axes();
ax.YDir = 'reverse';
hold on;
contourf(Rg,Cg,Fg);
ax.XAxisLocation = 'top';
cb = colorbar('Location', 'south');
cb.Position(2) = cb.Position(2)-0.11;
grid on;
saveas(gcf,filenames(1:end-4),'png');
delete(gcf);
end
  19 Kommentare
MS
MS am 8 Mai 2020
Bearbeitet: MS am 8 Mai 2020
hi ameer,
I want to label the colur bar as shown in the figure1.
my current code is labelling beside as shown in the figure below instead of labelling on the top as shown in the above figure1 .
h = colorbar;
xlabel(h, 'ω')
Kindly suggest a code.
MS
MS am 8 Mai 2020
I made the code to change the postion. Thanks.
pos = get(h,'Position');
h.Label.Position = [2 30]; % to change its position
h.Label.Rotation = 0; % to rotate the text

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Contour Plots 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