leaflet pattern . trying to add a path pattern not working - leaflet

based on the documentation here leaflet.pattern
i can create my custom patterns ,here is an example
I have done the same steps as mentioned in the example for our custom pattern . i have only changed the d element (related to svg path) .
but things did not went as i expected .
any help would be thankful .
Here is the code :
var mapCenter = new L.LatLng(50.68, -120.34);
var baseLayer = new L.TileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: '© OpenStreetMap contributors'
});
var _map = new L.Map("map", {
center: mapCenter,
zoom: 14,
layers: [baseLayer]
});
var shape = new L.PatternPath({
d: 'M10 0 L7 20 L25 20 Z',
fill: true
});
var pattern = new L.Pattern({width:50, height:50});
pattern.addShape(shape);
pattern.addTo(_map);
var circle = new L.Circle(mapCenter, 400.0, {
fillPattern: pattern,
fillOpacity: 1.0});
circle.addTo(_map);
I have only changed ( d: 'M10 0 L7 20 L25 20 Z')
to ('m206.38471,149.50017a1.52869,1.64413 0 0 1 3.0574,0a1.52869,1.64413 0 0 1 3.05738,0a1.52869,1.64413 0 0 1 3.0574,0a1.52869,1.64413 0 0 1 3.0574,0a1.52869,1.64413 0 0 1 3.05738,0a1.52869,1.64413 0 0 1 3.0574,0a1.52869,1.64413 0 0 1 3.05738,0a1.52869,1.64413 0 0 1 3.0574,0a1.52869,1.64413 0 0 1 3.0574,0a1.52869,1.64413 0 0 1 3.05738,0a1.52869,1.64413 0 0 1 3.0574,0a1.52869,1.64413 0 0 1 3.0574,0a1.52869,1.64413 0 0 1 3.05738,0a1.52869,1.64413 0 0 1 3.0574,0a1.52869,1.64413 0 0 1 3.05738,0a1.52869,1.64413 0 0 1 3.0574,0a1.52869,1.64413 0 0 1 3.0574,0a1.52869,1.64413 0 0 1 3.05738,0a1.52869,1.64413 0 0 1 3.0574,0a1.52869,1.64413 0 0 1 3.0574,0a1.52869,1.64413 0 0 1 3.05738,0a1.52869,1.64413 0 0 1 3.0574,0a1.52869,1.64413 0 0 1 3.05738,0a1.52869,1.64413 0 0 1 3.0574,0a1.52869,1.64413 0 0 1 3.0574,0a1.52869,1.64413 0 0 1 0,3.28828a1.52869,1.64413 0 0 1 0,3.28827a1.52869,1.64413 0 0 1 0,3.28828a1.52869,1.64413 0 0 1 0,3.28828a1.52869,1.64413 0 0 1 0,3.28827a1.52869,1.64413 0 0 1 0,3.28828a1.52869,1.64413 0 0 1 0,3.28827a1.52869,1.64413 0 0 1 0,3.28828a1.52869,1.64413 0 0 1 0,3.28828a1.52869,1.64413 0 0 1 0,3.28827a1.52869,1.64413 0 0 1 0,3.28828a1.52869,1.64413 0 0 1 0,3.28828a1.52869,1.64413 0 0 1 0,3.28827a1.52869,1.64413 0 0 1 0,3.28828a1.52869,1.64413 0 0 1 0,3.28827a1.52869,1.64413 0 0 1 0,3.28828a1.52869,1.64413 0 0 1 0,3.28828a1.52869,1.64413 0 0 1 0,3.28827a1.52869,1.64413 0 0 1 -3.0574,0a1.52869,1.64413 0 0 1 -3.0574,0a1.52869,1.64413 0 0 1 -3.05738,0a1.52869,1.64413 0 0 1 -3.0574,0a1.52869,1.64413 0 0 1 -3.05738,0a1.52869,1.64413 0 0 1 -3.0574,0a1.52869,1.64413 0 0 1 -3.0574,0a1.52869,1.64413 0 0 1 -3.05738,0a1.52869,1.64413 0 0 1 -3.0574,0a1.52869,1.64413 0 0 1 -3.0574,0a1.52869,1.64413 0 0 1 -3.05738,0a1.52869,1.64413 0 0 1 -3.0574,0a1.52869,1.64413 0 0 1 -3.05738,0a1.52869,1.64413 0 0 1 -3.0574,0a1.52869,1.64413 0 0 1 -3.0574,0a1.52869,1.64413 0 0 1 -3.05738,0a1.52869,1.64413 0 0 1 -3.0574,0a1.52869,1.64413 0 0 1 -3.0574,0a1.52869,1.64413 0 0 1 -3.05738,0a1.52869,1.64413 0 0 1 -3.0574,0a1.52869,1.64413 0 0 1 -3.05738,0a1.52869,1.64413 0 0 1 -3.0574,0a1.52869,1.64413 0 0 1 -3.0574,0a1.52869,1.64413 0 0 1 -3.05738,0a1.52869,1.64413 0 0 1 -3.0574,0a1.52869,1.64413 0 0 1 0,-3.28827a1.52869,1.64413 0 0 1 0,-3.28828a1.52869,1.64413 0 0 1 0,-3.28828a1.52869,1.64413 0 0 1 0,-3.28827a1.52869,1.64413 0 0 1 0,-3.28828a1.52869,1.64413 0 0 1 0,-3.28827a1.52869,1.64413 0 0 1 0,-3.28828a1.52869,1.64413 0 0 1 0,-3.28828a1.52869,1.64413 0 0 1 0,-3.28827a1.52869,1.64413 0 0 1 0,-3.28828a1.52869,1.64413 0 0 1 0,-3.28828a1.52869,1.64413 0 0 1 0,-3.28827a1.52869,1.64413 0 0 1 0,-3.28828a1.52869,1.64413 0 0 1 0,-3.28827a1.52869,1.64413 0 0 1 0,-3.28828a1.52869,1.64413 0 0 1 0,-3.28828a1.52869,1.64413 0 0 1 0,-3.28827a1.52869,1.64413 0 0 1 0,-3.28828')
any help would be thankfull

You can fix it by making x and y position of your svg path same as the sample's x and y positions.
I've put two paths in same svg file and opened it with an online editor.
As you can see in this screenshot, sample path is located top-left corner, but your path is located in the middle.
After setting its position same as sample's values: 6px, -1px pattern displayed like this:
used path: m8.278722,2.394142a1.52869,1.64413 0 0 1 3.0574,0a1.52869,1.64413 0 0 1 3.05738,0a1.52869,1.64413 0 0 1 3.0574,0a1.52869,1.64413 0 0 1 3.0574,0a1.52869,1.64413 0 0 1 3.05738,0a1.52869,1.64413 0 0 1 3.0574,0a1.52869,1.64413 0 0 1 3.05738,0a1.52869,1.64413 0 0 1 3.0574,0a1.52869,1.64413 0 0 1 3.0574,0a1.52869,1.64413 0 0 1 3.05738,0a1.52869,1.64413 0 0 1 3.0574,0a1.52869,1.64413 0 0 1 3.0574,0a1.52869,1.64413 0 0 1 3.05738,0a1.52869,1.64413 0 0 1 3.0574,0a1.52869,1.64413 0 0 1 3.05738,0a1.52869,1.64413 0 0 1 3.0574,0a1.52869,1.64413 0 0 1 3.0574,0a1.52869,1.64413 0 0 1 3.05738,0a1.52869,1.64413 0 0 1 3.0574,0a1.52869,1.64413 0 0 1 3.0574,0a1.52869,1.64413 0 0 1 3.05738,0a1.52869,1.64413 0 0 1 3.0574,0a1.52869,1.64413 0 0 1 3.05738,0a1.52869,1.64413 0 0 1 3.0574,0a1.52869,1.64413 0 0 1 3.0574,0a1.52869,1.64413 0 0 1 0,3.28828a1.52869,1.64413 0 0 1 0,3.28827a1.52869,1.64413 0 0 1 0,3.28828a1.52869,1.64413 0 0 1 0,3.28828a1.52869,1.64413 0 0 1 0,3.28827a1.52869,1.64413 0 0 1 0,3.28828a1.52869,1.64413 0 0 1 0,3.28827a1.52869,1.64413 0 0 1 0,3.28828a1.52869,1.64413 0 0 1 0,3.28828a1.52869,1.64413 0 0 1 0,3.28827a1.52869,1.64413 0 0 1 0,3.28828a1.52869,1.64413 0 0 1 0,3.28828a1.52869,1.64413 0 0 1 0,3.28827a1.52869,1.64413 0 0 1 0,3.28828a1.52869,1.64413 0 0 1 0,3.28827a1.52869,1.64413 0 0 1 0,3.28828a1.52869,1.64413 0 0 1 0,3.28828a1.52869,1.64413 0 0 1 0,3.28827a1.52869,1.64413 0 0 1 -3.0574,0a1.52869,1.64413 0 0 1 -3.0574,0a1.52869,1.64413 0 0 1 -3.05738,0a1.52869,1.64413 0 0 1 -3.0574,0a1.52869,1.64413 0 0 1 -3.05738,0a1.52869,1.64413 0 0 1 -3.0574,0a1.52869,1.64413 0 0 1 -3.0574,0a1.52869,1.64413 0 0 1 -3.05738,0a1.52869,1.64413 0 0 1 -3.0574,0a1.52869,1.64413 0 0 1 -3.0574,0a1.52869,1.64413 0 0 1 -3.05738,0a1.52869,1.64413 0 0 1 -3.0574,0a1.52869,1.64413 0 0 1 -3.05738,0a1.52869,1.64413 0 0 1 -3.0574,0a1.52869,1.64413 0 0 1 -3.0574,0a1.52869,1.64413 0 0 1 -3.05738,0a1.52869,1.64413 0 0 1 -3.0574,0a1.52869,1.64413 0 0 1 -3.0574,0a1.52869,1.64413 0 0 1 -3.05738,0a1.52869,1.64413 0 0 1 -3.0574,0a1.52869,1.64413 0 0 1 -3.05738,0a1.52869,1.64413 0 0 1 -3.0574,0a1.52869,1.64413 0 0 1 -3.0574,0a1.52869,1.64413 0 0 1 -3.05738,0a1.52869,1.64413 0 0 1 -3.0574,0a1.52869,1.64413 0 0 1 0,-3.28827a1.52869,1.64413 0 0 1 0,-3.28828a1.52869,1.64413 0 0 1 0,-3.28828a1.52869,1.64413 0 0 1 0,-3.28827a1.52869,1.64413 0 0 1 0,-3.28828a1.52869,1.64413 0 0 1 0,-3.28827a1.52869,1.64413 0 0 1 0,-3.28828a1.52869,1.64413 0 0 1 0,-3.28828a1.52869,1.64413 0 0 1 0,-3.28827a1.52869,1.64413 0 0 1 0,-3.28828a1.52869,1.64413 0 0 1 0,-3.28828a1.52869,1.64413 0 0 1 0,-3.28827a1.52869,1.64413 0 0 1 0,-3.28828a1.52869,1.64413 0 0 1 0,-3.28827a1.52869,1.64413 0 0 1 0,-3.28828a1.52869,1.64413 0 0 1 0,-3.28828a1.52869,1.64413 0 0 1 0,-3.28827a1.52869,1.64413 0 0 1 0,-3.28828
If you scale down your path, it is displayed like this:
used path: m7.27872,1.318623a0.528694,0.568619 0 0 1 1.057396,0a0.528694,0.568619 0 0 1 1.057389,0a0.528694,0.568619 0 0 1 1.057396,0a0.528694,0.568619 0 0 1 1.057396,0a0.528694,0.568619 0 0 1 1.057389,0a0.528694,0.568619 0 0 1 1.057396,0a0.528694,0.568619 0 0 1 1.057389,0a0.528694,0.568619 0 0 1 1.057396,0a0.528694,0.568619 0 0 1 1.057396,0a0.528694,0.568619 0 0 1 1.057389,0a0.528694,0.568619 0 0 1 1.057396,0a0.528694,0.568619 0 0 1 1.057396,0a0.528694,0.568619 0 0 1 1.057389,0a0.528694,0.568619 0 0 1 1.057396,0a0.528694,0.568619 0 0 1 1.057389,0a0.528694,0.568619 0 0 1 1.057396,0a0.528694,0.568619 0 0 1 1.057396,0a0.528694,0.568619 0 0 1 1.057389,0a0.528694,0.568619 0 0 1 1.057396,0a0.528694,0.568619 0 0 1 1.057396,0a0.528694,0.568619 0 0 1 1.057389,0a0.528694,0.568619 0 0 1 1.057396,0a0.528694,0.568619 0 0 1 1.057389,0a0.528694,0.568619 0 0 1 1.057396,0a0.528694,0.568619 0 0 1 1.057396,0a0.528694,0.568619 0 0 1 0,1.137245a0.528694,0.568619 0 0 1 0,1.137241a0.528694,0.568619 0 0 1 0,1.137245a0.528694,0.568619 0 0 1 0,1.137245a0.528694,0.568619 0 0 1 0,1.137241a0.528694,0.568619 0 0 1 0,1.137245a0.528694,0.568619 0 0 1 0,1.137241a0.528694,0.568619 0 0 1 0,1.137245a0.528694,0.568619 0 0 1 0,1.137245a0.528694,0.568619 0 0 1 0,1.137241a0.528694,0.568619 0 0 1 0,1.137245a0.528694,0.568619 0 0 1 0,1.137245a0.528694,0.568619 0 0 1 0,1.137241a0.528694,0.568619 0 0 1 0,1.137245a0.528694,0.568619 0 0 1 0,1.137241a0.528694,0.568619 0 0 1 0,1.137245a0.528694,0.568619 0 0 1 0,1.137245a0.528694,0.568619 0 0 1 0,1.137241a0.528694,0.568619 0 0 1 -1.057396,0a0.528694,0.568619 0 0 1 -1.057396,0a0.528694,0.568619 0 0 1 -1.057389,0a0.528694,0.568619 0 0 1 -1.057396,0a0.528694,0.568619 0 0 1 -1.057389,0a0.528694,0.568619 0 0 1 -1.057396,0a0.528694,0.568619 0 0 1 -1.057396,0a0.528694,0.568619 0 0 1 -1.057389,0a0.528694,0.568619 0 0 1 -1.057396,0a0.528694,0.568619 0 0 1 -1.057396,0a0.528694,0.568619 0 0 1 -1.057389,0a0.528694,0.568619 0 0 1 -1.057396,0a0.528694,0.568619 0 0 1 -1.057389,0a0.528694,0.568619 0 0 1 -1.057396,0a0.528694,0.568619 0 0 1 -1.057396,0a0.528694,0.568619 0 0 1 -1.057389,0a0.528694,0.568619 0 0 1 -1.057396,0a0.528694,0.568619 0 0 1 -1.057396,0a0.528694,0.568619 0 0 1 -1.057389,0a0.528694,0.568619 0 0 1 -1.057396,0a0.528694,0.568619 0 0 1 -1.057389,0a0.528694,0.568619 0 0 1 -1.057396,0a0.528694,0.568619 0 0 1 -1.057396,0a0.528694,0.568619 0 0 1 -1.057389,0a0.528694,0.568619 0 0 1 -1.057396,0a0.528694,0.568619 0 0 1 0,-1.137241a0.528694,0.568619 0 0 1 0,-1.137245a0.528694,0.568619 0 0 1 0,-1.137245a0.528694,0.568619 0 0 1 0,-1.137241a0.528694,0.568619 0 0 1 0,-1.137245a0.528694,0.568619 0 0 1 0,-1.137241a0.528694,0.568619 0 0 1 0,-1.137245a0.528694,0.568619 0 0 1 0,-1.137245a0.528694,0.568619 0 0 1 0,-1.137241a0.528694,0.568619 0 0 1 0,-1.137245a0.528694,0.568619 0 0 1 0,-1.137245a0.528694,0.568619 0 0 1 0,-1.137241a0.528694,0.568619 0 0 1 0,-1.137245a0.528694,0.568619 0 0 1 0,-1.137241a0.528694,0.568619 0 0 1 0,-1.137245a0.528694,0.568619 0 0 1 0,-1.137245a0.528694,0.568619 0 0 1 0,-1.137241a0.528694,0.568619 0 0 1 0,-1.137245

Related

Simulate obstacles in logical matrix

I'm writing an optimal path planning algorithm for one of my projects, and am a bit stuck on how to generate the map. In order to test my algorithm, I want to generate random maps that the object will pass through with obstacles in the way. To generate the maps I am making a logical array with "1" for wall or obstacle and "0" when there is nothing in the way. I am having some issues placing the obstacles however.
For now, this is what I've written in MATLAB (though I think the core idea can be solved in any language):
% lenx = length in x-direction of map [m]
% leny = length in y-direction of map [m]
% numObs = number of obstacles
% obsLoc = 2D array with the central location(s) of the obstacle(s)
% [x1, y1; x2 y2; ...]
% obsSize = size of the obstacles (all same size) [m]
% assume the obstacles are square.
% res = resolution of the map [cell/m]
%
% Outputs:
% map = 2D logical array which translates into a map
%
%---------------------------------------------------------
function map = createMap(lenx, leny, numObs, obsLoc, obsSize, res)
%Making map of the given size
map = zeros(leny*res, lenx*res);
%Adding walls
map(:,1) = 1;
map(:, lenx*res) = 1;
map(1,:) = 1;
map(leny*res, :) = 1;
%Recalculating obstacle size for this grid
obsSize = obsSize - 1;
%Adding obstacles
for i = 1:1:numObs
map(obsLoc(i,1)*res-obsSize*res:obsLoc(i,1)*res+obsSize*res,...
obsLoc(i,2)*res-obsSize*res:obsLoc(i,2)*res+obsSize*res) = 1;
end
end
The obsSize parameter is representing the dimension of one of the sides of the square obstacle. Here is a sample solution I ran:
>> createMap(10,10,1,[5,5],1,1)
ans =
1 1 1 1 1 1 1 1 1 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 1 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1
1 1 1 1 1 1 1 1 1 1
Looks good! But the issue begins for obstacle sizes and resolutions that are not 1 or 2...
>> createMap(10,10,1,[5,5],0.5,2)
ans =
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 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0 0 0 0 0 0 0 0 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
For the first one, we would expect there to be a 1 somewhere close to the middle, but it's nowhere to be found. In the second one, we'd expect to find 6 ones in each direction (3m * 3cell/m = 6 cell), but we are getting 8 (It's also possible that this is not what my code is calculating, but this is what I'm hoping it does. Neither case is working, and I think it has to do with this line:
Recalculating obstacle size for this grid
obsSize = obsSize - 1;
I'm pretty sure I do have to recalculate the object size so it fits to the grid, but how can I do this for any grid and obstacle? Is there a way to scale that "-1" such that it acts according to the size of the grid/obstacle?
Let me know what you come up with, and if there's any other glaring issues in my code?
Thanks!

How to visualize Markov Chain transition probabilities in MATLAB?

I want to visualize my Markov chain using a digraph. I am using the following lines of code:
mc = dtmc(TPM,'StateNames',namesStates);
graphplot(mc,'ColorNodes',true,'ColorEdges',true);
where namesStates is a cell array that contains the names (string) of each node of my MC.
Since the probabilities are so close to each other, I want to visualize the probabilities of each edge of the digraph or the transition rates. Is it possible?
EDIT:
Here is a TPM that I am using:
0,941033925686591 7,34322220590395e-05 0,000146864444118079 0,0220296666177119 0 0 0 0 0 0,0367161110295198 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0,000220296666177119 0,926053752386547 0,000293728888236158 0 0,0367161110295198 0 0 0 0 0 0,0367161110295198 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0,000367161110295198 0,000440593332354237 0,903730356880599 0 0 0,0587457776472316 0 0 0 0 0 0,0367161110295198 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
7,34322220590395e-05 0 0 0,940960493464532 7,34322220590395e-05 0,000146864444118079 0,0220296666177119 0 0 0 0 0 0,0367161110295198 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 7,34322220590395e-05 0 0,000220296666177119 0,925980320164488 0,000293728888236158 0 0,0367161110295198 0 0 0 0 0 0,0367161110295198 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 7,34322220590395e-05 0,000367161110295198 0,000440593332354237 0,903656924658540 0 0 0,0587457776472316 0 0 0 0 0 0,0367161110295198 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 7,34322220590395e-05 0 0 0,962990160082244 7,34322220590395e-05 0,000146864444118079 0 0 0 0 0 0 0,0367161110295198 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 7,34322220590395e-05 0 0,000220296666177119 0,962696431194008 0,000293728888236158 0 0 0 0 0 0 0 0,0367161110295198 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 7,34322220590395e-05 0,000367161110295198 0,000440593332354237 0,962402702305772 0 0 0 0 0 0 0 0 0,0367161110295198 0 0 0 0 0 0 0 0 0
0,00367161110295198 0 0 0 0 0 0 0 0 0,937362314583639 7,34322220590395e-05 0,000146864444118079 0,0220296666177119 0 0 0 0 0 0,0367161110295198 0 0 0 0 0 0 0 0
0 0,00367161110295198 0 0 0 0 0 0 0 0,000220296666177119 0,922382141283595 0,000293728888236158 0 0,0367161110295198 0 0 0 0 0 0,0367161110295198 0 0 0 0 0 0 0
0 0 0,00367161110295198 0 0 0 0 0 0 0,000367161110295198 0,000440593332354237 0,900058745777647 0 0 0,0587457776472316 0 0 0 0 0 0,0367161110295198 0 0 0 0 0 0
0 0 0 0,00367161110295198 0 0 0 0 0 3,85519165809957e-05 0 0 0,937323762667058 7,34322220590395e-05 0,000146864444118079 0,0220296666177119 0 0 0 0 0 0,0367161110295198 0 0 0 0 0
0 0 0 0 0,00367161110295198 0 0 0 0 0 5,07906202575023e-05 0 0,000220296666177119 0,922331350663338 0,000293728888236158 0 0,0367161110295198 0 0 0 0 0 0,0367161110295198 0 0 0 0
0 0 0 0 0 0,00367161110295198 0 0 0 0 0 5,87457776472316e-05 0,000367161110295198 0,000440593332354237 0,900000000000000 0 0 0,0587457776472316 0 0 0 0 0 0,0367161110295198 0 0 0
0 0 0 0 0 0 0,00367161110295198 0 0 0 0 0 3,85519165809957e-05 0 0 0,959353429284770 7,34322220590395e-05 0,000146864444118079 0 0 0 0 0 0 0,0367161110295198 0 0
0 0 0 0 0 0 0 0,00367161110295198 0 0 0 0 0 5,07906202575023e-05 0 0,000220296666177119 0,959047461692858 0,000293728888236158 0 0 0 0 0 0 0 0,0367161110295198 0
0 0 0 0 0 0 0 0 0,00367161110295198 0 0 0 0 0 5,87457776472316e-05 0,000367161110295198 0,000440593332354237 0,958745777647232 0 0 0 0 0 0 0 0 0,0367161110295198
0 0 0 0 0 0 0 0 0 0,00734322220590395 0 0 0 0 0 0 0 0 0,970406814510207 7,34322220590395e-05 0,000146864444118079 0,0220296666177119 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0,00734322220590395 0 0 0 0 0 0 0 0,000220296666177119 0,955426641210163 0,000293728888236158 0 0,0367161110295198 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0,00734322220590395 0 0 0 0 0 0 0,000367161110295198 0,000440593332354237 0,933103245704215 0 0 0,0587457776472316 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0,00734322220590395 0 0 0 0 0 4,40593332354237e-05 0 0 0,970362755176972 7,34322220590395e-05 0,000146864444118079 0,0220296666177119 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0,00734322220590395 0 0 0 0 0 5,50741665442796e-05 0 0,000220296666177119 0,955371567043619 0,000293728888236158 0 0,0367161110295198 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0,00734322220590395 0 0 0 0 0 6,16830665295932e-05 0,000367161110295198 0,000440593332354237 0,933041562637686 0 0 0,0587457776472316
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0,00734322220590395 0 0 0 0 0 4,40593332354237e-05 0 0 0,992392421794684 7,34322220590395e-05 0,000146864444118079
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0,00734322220590395 0 0 0 0 0 5,50741665442796e-05 0 0,000220296666177119 0,992087678073139 0,000293728888236158
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0,00734322220590395 0 0 0 0 0 6,16830665295932e-05 0,000367161110295198 0,000440593332354237 0,991787340284917
instead of:
mc = dtmc(TPM,'StateNames',namesStates);
We can do:
mc = dtmc(TPM);
In the documentation you can find the 'LabelEdges' parameter, when set to true the probability is also displayed.
graphplot(mc,'ColorNodes',true,'ColorEdges',true,'LabelEdges',true);

Drawing a non-bipartite graph in MATLAB

I am looking to draw a graph in MATLAB. My graph is non-bipartite and the matrix for the graph is:
A=[0 1 0 0 0 1 0 0 0 0 0 1 0 0 1 0 %1
1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 %2
0 1 0 1 0 0 1 0 0 0 0 0 0 0 0 0 %3
0 0 1 0 1 0 0 0 1 0 0 0 0 0 1 0 %4
0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 1 %5
1 0 0 0 1 0 1 0 0 1 0 0 0 0 0 0 %6
0 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 %7
0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 %8
0 0 0 1 0 0 0 1 0 1 0 0 1 0 0 0 %9
0 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0 %10
0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 1 %11
1 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 %12
0 0 0 0 0 0 0 0 1 0 0 1 0 1 0 0 %13
0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 %14
1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 %15
0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0]; %16
When this graph is drawn in MATLAB, the node numbered 16 is to the left of the graph but this should be in the centre.
Is there a way to set up my matrix so that the node 16 is in the centre making the graph non-bipartite?
Not sure how you're plotting the graph, but on my Win10-x64 R2017b I get that 16 is the closest point to the center:
function q47392076
A=[0 1 0 0 0 1 0 0 0 0 0 1 0 0 1 0 %1
1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 %2
0 1 0 1 0 0 1 0 0 0 0 0 0 0 0 0 %3
0 0 1 0 1 0 0 0 1 0 0 0 0 0 1 0 %4
0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 1 %5
1 0 0 0 1 0 1 0 0 1 0 0 0 0 0 0 %6
0 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 %7
0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 %8
0 0 0 1 0 0 0 1 0 1 0 0 1 0 0 0 %9
0 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0 %10
0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 1 %11
1 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 %12
0 0 0 0 0 0 0 0 1 0 0 1 0 1 0 0 %13
0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 %14
1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 %15
0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0]; %16
G = graph(A);
figure(); plot(G);
end

Matrix Exponentiation in Galois Field 2

I am confusing about exponentiation of matrix in Galois Field 2. Assume that I have a matrix that is represented in Galois Field 2 (GF2). I want to take exponentiation of 30. That is,
A^30
In the matlab we have two way to do it.
First, We perform A power 30 and take mod of 2 (Note that A is a double matrix)
A1=mod(A^30,2)
Second way, we convert A to galois matrix and take exponentiation
A=gf(A,2)
A2=A^30
Actually, two way must same result. However, when I check A1 and A2. They have a different result. What is happen in here? Thanks
Let see my A matrix
A =
1 1 0 1 1 1 0 1 0 0 0 1 0 1 0
0 0 0 1 0 1 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 1 0 1 0 0 0 1
1 0 1 1 0 0 0 0 0 0 1 1 1 0 0
1 0 1 0 0 0 0 1 0 0 0 0 0 0 0
0 1 0 1 1 1 1 1 0 1 1 1 1 0 1
0 0 0 1 0 0 0 1 0 0 1 0 0 0 0
0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
1 0 0 1 0 1 0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 1 0 0 1 1
1 0 1 0 0 0 0 0 0 0 1 0 0 0 1
0 1 0 0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zero;one;two;three;four;five;six;seven;eight;nine];
and create a hopfield with newhop
net = newhop(target);
[Y,Pf,Af] = sim(net,10,[],target);
I conclusion this from matlab website
but really I don't know How I achive this
my project is detect digits by hopfield network
appreciate any orgency help
Try:
target =[zero;one;two;three;four;five;six;seven;eight;nine]';
Then, for a test:
test={three'};
[Y,Pf,Af] = sim(net,{1 5},{},test);
Y{1}
You'll notice that Y{1}-three' is very close to zero, which means that your network does its job. Now, in order to recognize the digit you enter, you need to subtract Y{1} from the matrix of digits and check the row the elements of which are closest to zero. This will indicate you the digit you entered.