Tag: matrix

55 votes
4 answers
1.3K views
Function for 'does matrix contain value X?'

Is there a built in MATLAB function to find out if a matrix contains a certain value? (ala PHP's in_array

avatar
Majorie
0 1 0 9
asked 07 September, 2021
55 votes
7 answers
1.8K views
How can I count the number of elements of a given value in a matrix?

Does anyone know how to count the number of times a value appears in a matrix? For example, if I have a 1500

avatar
Thurman
0 1 0 9
asked 07 September, 2021
57 votes
8 answers
398 views
How do I iterate through each element in an n-dimensional matrix in MATLAB?

I have a problem. I need to iterate through every element in an n-dimensional matrix in MATLAB. The problem is

avatar
Chaya
0 1 0 9
asked 07 September, 2021
55 votes
11 answers
842 views
How can I apply a function to every row/column of a matrix in MATLAB?

You can apply a function to every item in a vector by saying, for example, v + 1, or you can use the function

avatar
Adolfo
0 1 0 9
asked 07 September, 2021
51 votes
12 answers
1.9K views
Why is MATLAB so fast in matrix multiplication?

I am making some benchmarks with CUDA, C++, C#, Java, and using MATLAB for verification and matrix generation.

avatar
Wei
0 1 0 9
asked 07 September, 2021
68 votes
9 answers
456 views
How can I index a MATLAB array returned by a function without first assigning it to a local variable?

For example, if I want to read the middle value from magic(5), I can do so like this: M = magic(5); value = M

avatar
Rudy
0 1 0 9
asked 07 September, 2021
58 votes
4 answers
2.7K views
How to transform numpy.matrix or array to scipy sparse matrix

For SciPy sparse matrix, one can use todense() or toarray() to transform to NumPy matrix or array. What are th

avatar
Patsy
0 1 0 9
asked 07 September, 2021
54 votes
7 answers
1.3K views
Difference between numpy.array shape (R, 1) and (R,)

In numpy, some of the operations return in shape (R, 1) but some return (R,). This will make matrix multiplica

avatar
Solomon
0 1 0 9
asked 07 September, 2021
62 votes
5 answers
560 views
What are the differences between numpy arrays and matrices? Which one should I use?

What are the advantages and disadvantages of each? From what I've seen, either one can work as a replace

avatar
Sachiko
0 1 0 9
asked 07 September, 2021