[Solved] How do i select a number in a matrix in c?

If you mean number in a matrix as follows (example for matrixSize == 4): 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 you can just calculate indexes from number matrixValues[number/matrixSize][number%matrixSize] EDIT: For case when your 2D arreay defined as int matrixValues[matrixSize][matrixSize]; All elements allocated in memory sequentially, … Read more

[Solved] Error using .* Matrix dimensions must agree?

As your input image I is a color image (RGB), the array I is three-dimensional: width-by-height-by-3, because for each pixel you need three values: red, green and blue. The output of butterhp, however, is always width-by-height, so you are trying to multiply a 2D-array times a 3D-array, which fails of course. Often, processing in grayscale … Read more

[Solved] Whats wrong with the c code?

A 2D array does not decay to a pointer to a pointer. By using: maxim=findMax((int **)a,m,n); you are forcing the compiler to ignore your error. Instead of int findMax(int **a,int m,int n) use int findMax(int a[][20],int m,int n) and then, call the function simply using: maxim=findMax(a,m,n); You said: The problem statement says that int findMax(int … Read more

[Solved] Passing to a same function matrices with different sizes of both dimensions

You should use a typedef so that you don’t have to use any awful syntax: using matrix_t = int[3][3]; And you should pass your args by reference whenever possible: void handle_matrix(const matrix_t &mat){ // do something with ‘mat’ } If you want to use the original syntax without a typedef: void handle_matrix(const int (&mat)[3][3]){ // … Read more

[Solved] How to set a matrix as a parameter to a function

You can represent the matrix as a vector<vector<int> >. Try something like this: #include <vector> using namespace std; void myFunction(const vector<vector<int> >& matrix) { // do something w/ matrix passed in… } int main() { // create a 3×4 matrix initialized to all zero const size_t rowCount = 3; const size_t colCount = 4; vector<vector<int> … Read more

[Solved] How to add a value in a matrix and make it decrease in radial way? [closed]

[EDIT] So based on you’re edit i thought this solution. Since you don’t specify any programming language i’ll use some c-like functional programming. I’ll leave you the work of transforming it to object oriented if you need it. Input: Global maxtrix that starts in M[0,0] and ends in M[100’000, 100’000] (Note that, to make it … Read more

[Solved] R create a matrix of occurence [closed]

Ok, still not perfectly clear, but I THINK that presence is now an adjacency matrix, where the columns represent users and the rows represent events, so presence[i,j] indicates that user i attended event j. If I’m interpreting it correctly then counts seems to be the co-occurrence matrix, correct? count[i,j] should record the number of events … Read more

[Solved] Create a larger matrix in special case [closed]

I’m assuming that A and B are coordinates, and you want to “draw” the plot in matrix form, so try this: c = flipud(full(sparse(B, A, B))); I added flipud to adjust the positive direction of the y-axis upwards. Alternatively, you can obtain a binary matrix using this: c1 = flipud(full(sparse(B, A, ones(size(A))))); Important: for this … Read more