- The brute clearing header: "close all, clear all, clc" is brute. Especially "clear all" is a waste of time only.
- Do not use cd() to change into a directory containing data. Remember that each callback of a GUI or timer could call cd also and afterwards the function will show unexpected behaviour. Define the folder as a variable and use fullfile() to access the files with a full path.
- Add only folders containing functions to Matlab's path. Using addpath for data folders will increase the chance for a perfect confusion. Use absolute path names instead, see above.
- Do not call load() without catching the output in a variable. Doing so will create variables dynamically. This impedes the JIT acceleration (the code can run up to 100 times slower) and make it much harder to debug the code, because it is impossible to guess in advance, which variables are imported.
How to match to figure in Matlab?
3 次查看(过去 30 天)
显示 更早的评论
Hi all,
I am trying to match two figures using matlab. The first figure correspond to the limit of the border of land (of UK and Ireland), presented in attached file call border.png. The second figure correspond to vessal density data, presented in attached file call vessel_density.png.
When I tried to add the two figures together (see code below), I obtained an odd figure. The results is presnted in attached file call test.png. As we can notice, the border figure has rotate by 90degrees and are on the left of the new figure, when the figure of the veesel density is only showing a small part of it. I tried to change the value of xlim and y lim, and results hsow all the vessel density data but hte border are limited to the top leftt of the figure (result not shown).
Does anybody have an idea on how to fix this, please?
Regards
%% Nice plot
close all
clear all
clc
% assign the path to your working directory:
cd ('E:\publi\Waiting-room\MSC project\Data_emodnet_fisheries\Vessel_density\');
% add path to TelemacTolls functions (i.e. to read in telemac files into MATLAB):
addpath ('C:\Matlab_download\m_map1.4\m_map\data\');
load Average.mat
% limit of the domain for UK and Ireland border:
latlim = [49.5 61];
lonlim = [-11 4];
S = gshhs('gshhs_h.b', latlim, lonlim);
levels = [S.Level];
L1 = S(levels == 1);
figure
plot ([L1.Lon],[L1.Lat], '-k');
xlim([-11 4]);
ylim([49.5 61]);
hold on
cmap = turbo;
cmap(1:4,:)=ones(4,3);
imshow(Average,Colormap=cmap);
limits = [0,3];
c = colorbar;
set(gca,'clim',limits([1,end]));
c.FontSize = 14;
c.Label.String = 'Fishing vessel density (h/m2/month)';
c.Label.FontSize = 14;
2 个评论
Jan
2022-3-16
Some hints:
回答(1 个)
Jan
2022-3-16
imshow changes the ydir property of the axes. Better add another axes object at the same position as the first one to avoid confusions.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Identification 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!