matrix

Algorithm to find same element from a point in a random matrix

倖福魔咒の 提交于 2019-12-25 17:00:37
问题 I'm wondering on how can I do to find, in a random matrix, each same elements from a particular point, and around this point. It's easier to explain in an example : So, in green it is the point that the player chooses. How can I get the position of all these "X" (only lines and columns, not diagonal) ? I thought about an algorithm like Dijkstra or Bellman Ford ? I hope you understand, and sorry for my bad english. Thanks 回答1: Something like depth-first search (DFS) or breadth-first search

Simple way in matlab to count number of adjacent non-zero values in matrix?

百般思念 提交于 2019-12-25 17:00:29
问题 I am fairly new at Matlab, and I have to create a minesweeper game on matlab where I generate a random matrix A of ones and zeroes, where ones are mines and zeroes are not. Then I have to create a matrix B, where each element has to be the number of adjacent mines (or ones) from matrix A. The ones (or mines) become 10s in matrix B. for example if A = [0 1 0 1 0 1] B= [2 10 2 10 3 10] I don't know how to set up matrix B so that it can count the number of adjacent ones of matrix A and set that

Sorting matrix diagonal wise and indexes are given as rank using matlab

故事扮演 提交于 2019-12-25 17:00:11
问题 This first matrix table1 contains normalized values for 5 names.I need to perform some operations on this matrix and I have to obtain second matrix as shown in table2. Diagonal elements of table2 should obtained by giving rank(ordinal value) to each value.That means highest element is given 5th rank and next 4th 3rd and so on. Remaining elements of table obtained by giving rank to each value starting from 4 because only 4 elements remaining. Because already we are given rank to diagonal

Simple way in matlab to count number of adjacent non-zero values in matrix?

一世执手 提交于 2019-12-25 17:00:03
问题 I am fairly new at Matlab, and I have to create a minesweeper game on matlab where I generate a random matrix A of ones and zeroes, where ones are mines and zeroes are not. Then I have to create a matrix B, where each element has to be the number of adjacent mines (or ones) from matrix A. The ones (or mines) become 10s in matrix B. for example if A = [0 1 0 1 0 1] B= [2 10 2 10 3 10] I don't know how to set up matrix B so that it can count the number of adjacent ones of matrix A and set that

Matlab: Filling up matrix rows using moving intervals from a column vector without a for loop

若如初见. 提交于 2019-12-25 16:58:17
问题 I built a function for outliers detection and it worked quite well, but given the huge amount of data I'm working on I needed to remove the "for loop", so here we have the vectorized version (or at least what I think is a vectorized version of my code). Calling the function the following parameters are intialized by the user, I am working with the following: alpha=3 gamma=0.5 k=5 The series "price" exist in the workspace, is linked when calling the function. I think I almost did it but I am

OpenGL ES20 - Light a cube, how to get normals?

ぃ、小莉子 提交于 2019-12-25 16:57:23
问题 To add some lightning to my OpenGL ES20 cube, I need to calculate the normals for each plane. I've found a "tutorial" on lightning, but they simply hard-coded the normals into the cube, which appears to me as not the best option, since it seems limited? So my approach to the cube is as follows: private float[] mVertices = { -1, -1, -1, // bottom left 1, -1, -1, // bottom right back 1, 1, -1, // top right -1, 1, -1, // top left -1, -1, 1, // bottom left 1, -1, 1, // bottom right front 1, 1, 1,

effective way of transformation from 2D to 1D vector

人走茶凉 提交于 2019-12-25 16:57:20
问题 i want to create 1D vector in matlab from given matrix,for this i have implemented following algorithm ,which use trivial way % create one dimensional vector from 2D matrix function [x]=one_dimensional(b,m,n) k=1; for i=1:m for t=1:n x(k)=b(i,t); k=k+1; end end x; end when i run it using following example,it seems to do it's task fine b=[2 1 3;4 2 3;1 5 4] b = 2 1 3 4 2 3 1 5 4 >> one_dimensional(b,3,3) ans = 2 1 3 4 2 3 1 5 4 but generally i know that,arrays are not good way to use in matlab

Converting vectors into 2D matrix [duplicate]

谁都会走 提交于 2019-12-25 16:51:50
问题 This question already has answers here : Reshape three column data frame to matrix (“long” to “wide” format) [duplicate] (6 answers) Closed 6 years ago . I have data that looks like this: total position division 34 C ATL 34 C CEN 47 C NE 46 C NW 44 C PAC 42 C SE 57 D ATL 50 D CEN 44 D NE 52 D NW 42 D PAC 52 D SE 29 L ATL 34 L CEN 28 L NE 34 L NW 29 L PAC 24 L SE 26 R ATL 33 R CEN 25 R NE 29 R NW 24 R PAC 35 R SE I wish to transform it into a 2D matrix which can then be used for a Chi squared

Converting vectors into 2D matrix [duplicate]

我的梦境 提交于 2019-12-25 16:51:12
问题 This question already has answers here : Reshape three column data frame to matrix (“long” to “wide” format) [duplicate] (6 answers) Closed 6 years ago . I have data that looks like this: total position division 34 C ATL 34 C CEN 47 C NE 46 C NW 44 C PAC 42 C SE 57 D ATL 50 D CEN 44 D NE 52 D NW 42 D PAC 52 D SE 29 L ATL 34 L CEN 28 L NE 34 L NW 29 L PAC 24 L SE 26 R ATL 33 R CEN 25 R NE 29 R NW 24 R PAC 35 R SE I wish to transform it into a 2D matrix which can then be used for a Chi squared

Irregular Numpy matrix

馋奶兔 提交于 2019-12-25 16:47:43
问题 In Numpy, it appears that the matrix can simply be a nested list of anything not limited to numbers. For example import numpy as np a = [[1,2,5],[3,'r']] b = np.matrix(a) generates no complaints. What is the purpose of this tolerance when list can treat the object that is not a matrix in the strict mathematical sense? 回答1: What you've created is an object dtype array: In [302]: b=np.array([[1,2,5],[3,'r']]) In [303]: b Out[303]: array([[1, 2, 5], [3, 'r']], dtype=object) In [304]: b.shape Out