matlab indices not in range? [closed] - matlab

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm trying to write the optimal quantization for IP.
I'm new to matlab and in this code, i'm trying to go over every pixel in every interval of Z, multiply it with it's histogram and sum it , so I can calculate the optimal Q.
problem : Attempted to access hist(257);index out of bounds because numel(hist)=256.
for i=1:K,
for j=(Z(i)):Z(i+1),
sum1=(j)*hist(j+1)+sum1;
count=count+hist(j+1);
end
end

The error is telling you that you cannot access hist(257) because the array hist only has 256 elements in it. Note that hist is also a built in function name so you really ought to consider giving your variable a different name.
How to solve:
Think carefully about your code, and what you are trying to achieve. What are Z. hist and K? What is the largest value that j can reach (=Z(i+1))? That is the value with which you are indexing hist, and apparently hist is not that big. What then is the shape of each variable?

Related

Regression Matlab [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 days ago.
Improve this question
Identification of brain areas after language stimuli
Hi guys, I'm trying to solve a problem with my code in matlab. My goal is to identificate brain areas associated to language stimuli. After I performed some tasks, i arrived to plot the convolution between the BOLD signal and square signal (stimuli). Now, my goal is to perform a regression using regress between the convolution result (1x481 matrix) and a matrix containing the number of voxels of my brain images (92614x39) where the rows are the voxels and 39 are the MRI scans. So, the two matrices have different size and I have no idea how to perform a regression. Anyone could help me?

What does linsolve(A,B) return when the number of equations is larger then number of variables? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I by accident put a matrix A with far more rows then columns into linsolve(A,B). So it should be inconsistent system of equations. However what I got was a 'solution' which fits my task far better. So what exactly does it return when you have more columns then rows?
What you have seems to be an overdetermined linear system, that can be solved by the least-square method.
If your matrix A has more rows than columns (m > n) it means that you have more equations than unknowns, so an exact solution can be almost impossible to find. What you can obtain is a good enough solution that minimizes the error.
You can refer to the page Overdetermined system for more insights.

what are the conclusions obtained from this box plot? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have plotted the standard deviation of different regions.Can anyone help me to get the conclusions from this boxplot. I just want to conclude the properties of regions. In this figure, eigth object is odd one. What is the significance of whiskers?
How to change the xlabel as region1 ,region2 etc
Coclusions: wide part of your data does not follow a normal distribution. You need something like Violin Plots to see what is rally happening in your data.
Specially for 3-7, as it seems that the number of the outliers is too big.
But remember: Conclusions are obtained from data, not from the plotting option you chose for your data!
about changing the xlabel.... have you tried the function xlabel....?

How to vectorize for loops in Matlab? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a matrix where each row is a vector of data points and I want to predict labels for each row using a classifier. What I'm doing now is reading each row of the matrix one by one in a for loop and running the classifier on each entry. There's room for parallelization here since each row's outcome is independent of the other rows. Does MATLAB have any function to speed this up?
Assuming you wrote the classifier yourself this is possible. Instead of passing one row to the classifier you would pass the complete matrix. Within the classifier you would have to change the way the prediction is made. Assuming you use a mathematical formula to calculate the outcome you would have to alter it using element-wise operators. An example of using element-wise operators instead of a for-loop:
Example data
a = [1,2;
3,4;
5,6]
Using a for-loop
p1= zeros(size(a,1),1);
for i=1:size(a,1)
p1(i) = a(i,1)*2 + a(i,2)^2;
end
Using vectorization
p2 = a(:,1).*2 + a(:,2).^2
Element-wise operators:
http://nl.mathworks.com/help/matlab/ref/times.html?searchHighlight=element-wise
http://nl.mathworks.com/help/matlab/ref/power.html?searchHighlight=element-wise
It is highly recommended to use vectorization instead of for-loops since it's much more efficient.

Image processing: Minimizing laplacian norm with boundary conditions [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I'm trying to minimize this function (by A):
argmin_A (||L(A)||^2 + a||A-B||^2*)
where:
A is a MxN image L is the Laplacian Operator
||.|| is the usual norm (Frobrenius)
a is a weight parameter
B is a matrix of size (M+2*k)xN
where k is an integer parameter.
(*) indicates that we just consider the pixels in the boundary (we want to preserve in A the pixels in the boundary of B).
Maybe the problem has a trivial solution, but I'm absolutely blocked.
If you need more details, it's (4) equation in this paper.
I will be very grateful for any help provided.
Without looking carefully at that paper, gridfit does essentially that, although it does not employ the boundary conditions you ask for. You could certainly write what you want however, or you could simply apply a weight to the boundary points. This is not a difficult problem, but in order to solve it efficiently, you would want to employ the sparse matrix capabilities of MATLAB.