Azzera filtri
Azzera filtri

Index exceeds matrix dimensions, error problem

3 visualizzazioni (ultimi 30 giorni)
Grace
Grace il 7 Giu 2014
Risposto: chaima kadess il 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?

Risposte (3)

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

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by