Filter löschen
Filter löschen

Index exceeds matrix dimensions, error problem

3 Ansichten (letzte 30 Tage)
Grace
Grace am 7 Jun. 2014
Beantwortet: chaima kadess am 8 Apr. 2018
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?

Antworten (3)

Star Strider
Star Strider am 7 Jun. 2014
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 am 7 Jun. 2014
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 am 8 Apr. 2018
I also faced the same error with this ligne ?? I= dicomread(fileNames{numFrames});

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by