Info
This question is closed. Reopen it to edit or answer.
Problems in accessing 2nd column of matrix
1 view (last 30 days)
Show older comments
I know this is a very simple problem, but I cant seem to find what is the issue as it seems logical.
I tried instances when xx is a column vector or horizontal vector, but it doesnt make a difference.
Count is the final number of data points i want to obtain. E.g.
count = 10
for k = 1:(length(xx)-1)
temp = *data* (xx(k):xx(k+1));
mat(:,k) = interrp(temp, count);
end
interrp is a function that was written to use the i
interp1 function to use the method 'spline'.
My code always stop after finishing filling up the 1st column. This is the error that I receive: Subscripted assignment dimension mismatch.
Answers (2)
Geoff Hayes
on 11 Apr 2015
Edited: Geoff Hayes
on 11 Apr 2015
Mich - what are the dimensions of the array that the interrp function is returning? The error message Subscripted assignment dimension mismatch typically means that the code is trying to insert more data than it can fit into the destination array. For example,
x = zeros(3,42);
x(:,2) = randi(255,4,1);
returns the same error because I am trying to assign a 4x1 matrix into a 3x1 destination. Put a breakpoint at the line
mat(:,k) = interrp(temp, count);
then run your code and verify that what interrp is returning is too large for the mat(:,k) destination.
You may also want to pre-size mat prior to entering the for loop so that you know exactly what you are trying (and what you are able) to assign to this matrix.
2 Comments
Geoff Hayes
on 11 Apr 2015
Mich - see http://blogs.mathworks.com/videos/2010/09/02/using-debugger-to-walk-through-code to step through the code using the debugger.
pfb
on 11 Apr 2015
Edited: pfb
on 11 Apr 2015
Hi,
Your code is very obscure. What exactly do you want do attain? In particular, this line
temp = xx(xx(k):xx(k+1));
looks weird, especially if xx does not contain positive integers. Even in that case, I kind of see why matlab complains about the dimension mismatch. What is xx?
1 Comment
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!