Index exceeds matrix dimensions, error problem

1 次查看(过去 30 天)
function cut=UDcutcut(n,s,p)
initial=[ 1 3;2 6; 3 2; 4 5; 5 1; 6 4; 7 7];
[r s]=size(initial);
new_initial=cell(s,1);
UT=cell(s,r);
for col=1:s
temp=sortrows(initial,col);
new_inital{col}=temp;
for m=1:p
if m>n
UT{col,m}=new_initial{col}(m-n:m-1,:);
else
j=1:m-1;
a=new_initial{col}(j,:);
i=m:n;
b=new_initial{col}(i+p-n,:);
UT{col,m}=cat(1,a,b);
end
end
end
cut=UT;
end
When I run the code, the programme shows me:
>> UDcutcut(4,2,7)
Index exceeds matrix dimensions.
Error in UDcutcut (line 17)
b=new_initial{col}(i+p-n,:);
I can't figure it out where is the problem, anyone help?

回答(3 个)

Star Strider
Star Strider 2014-6-7
I can tell you what’s wrong, but only you know how to fix them:
On the first iteration of the ‘j’ loop, m=1, so j can’t go from 1 to zero unless you tell it to decrement. So j is empty.
In the line throwing the error that assigns b, i is a (1x4) vector that in this situation isn’t allowed as a subscript defining b,a scalar.
They may be other problems, but you have to fix these first to get your code to run.

SRI
SRI 2014-6-7
Check For the size of the m and n which may exceeds the level beyond the loop, so you face this error. instead try changing range for m it may result better

chaima kadess
chaima kadess 2018-4-8
I also faced the same error with this ligne ?? I= dicomread(fileNames{numFrames});

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by