How to index function-matrices?
matlab - Use a vector as an index to a matrix - Stack Overflow
Array/Matrix Indexing
Indexing a matrix intuitively
Videos
Using the function sub2ind to create a linear index is the typical solution to this problem, as shown in this closely-related question. You could also compute a linear index yourself instead of calling sub2ind.
However, your case may be simpler than those in the other questions I linked to. If you're only ever indexing a single point with your current_point vector (i.e. it's just an n-element vector of subscripts into your n-dimensional matrix), then you can use a simple solution where you convert current_point to a cell array of subscripts using the function num2cell and use it to create a comma-separated list of indices. For example:
current_point = [1 2 3 ...]; % A 1-by-n array of subscripts
subCell = num2cell(current_point); % A 1-by-n cell array of subscripts
output_matrix(subCell{:}) = val; % Update the matrix point
The operation subCell{:} creates the equivalent of typing subCell{1}, subCell{2}, ..., which is the equivalent of typing current_point(1), current_point(2), ....
I know it is too late but for anybody who will find this topic. the easiest way that work for me is to use: diag(A (x(:),y(:)) );
unfortunately this works only if you need to get values from the matrix, not for changing values
Hello. I have a problem regarding arrays or matrices, in that i need to check two numbers at the same time for condition.
The Problem - I have a list of n students. In the list there is 2 numbers for each students.
The first number represents student average grade, the second number represents if a student is eligible for a scholarship. If second number is 0, they are eligible, if it is 1, they are not.
An example of my list would be like this:
8.5 0
9.6 0
9.2 1
4.5 0
8.5 1
Additional thing is that, to be eligible for scholarship, not only second number has to be 0, but
the average grade must be > 8.5.
So, first of all, i need to check if a student, or given line first number is more >= 8.5 AND second number is == 0, secondly, if these conditions are met, i need to store this line in a new array.
I hope i described my problem clearly.
I have achieved to solve it using loops, for loops to be specific, but my teacher is forcing to solve this problem using indexing, whatever that means, or i risk getting bad grade. I just can not wrap my head around it. Hope you can help.