Info
此问题已关闭。 请重新打开它进行编辑或回答。
Problems in accessing 2nd column of matrix
1 次查看(过去 30 天)
显示 更早的评论
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.
回答(2 个)
Geoff Hayes
2015-4-11
编辑:Geoff Hayes
2015-4-11
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 个评论
Geoff Hayes
2015-4-11
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
2015-4-11
编辑:pfb
2015-4-11
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 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!