[Solved] Passing a matrix of structs to a function [duplicate]

A matrix is an array of arrays, so you could use a pointer to a pointer to mystruct, as well and the number of rows and columns so the function knows how to handle it: void myfunction(mystruct** matrix, int rows, int columns) { // Your logic goes here… } 3 solved Passing a matrix of … Read more

[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] How to extract out a non-continuous matrix from a larger matrix based on a list [closed]

You can do it by: a =[ [0,1,0,0,0,1], [4,1,0,3,2,0], [0,0,1,0,0,0], [0,1,0,0,1,0], [0,0,0,0,1,0], [0,0,0,0,0,0], ] b = [0, 1, 3] c = [[a[i][j] for j in b] for i in b] print(c) # ===> # [[0, 1, 0], [4, 1, 3], [0, 1, 0]] (Anyway, Python2 is no longer supported: link. I recommend you use Python3+NumPy, … Read more

[Solved] Without binarysearch,how can I do a search in matrix? [closed]

Your question is really vague. Rather than coming here asking a vague question you should provide some code snippets, explain what your have tried and what is going wrong. This will help people answer your question, and not down-vote your question to hell (like what is happening now). With that being said i’ll take a … 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] Matlab sort every other column

For each set of two columns, you can use sortrows. for idx=1:2:size(M,2) M(:,idx:idx+1)=sortrows(M(:,idx:idx+1),2) end 2 solved Matlab sort every other column