looping through an empty array error
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
i m running a loop through arrays of cells
if true
%
for i =1:32
dummy=array{i};
funny=size(dummy(i));
for e=1:funny
diff12(e,i) = (dummy(e,11)- dummy(e,12)); %P-code
diff23(e,i) = (c/((dummy(e,8))-((fL1/fL2)*dummy(e,9))))*100; %Phase
end
end code end
in some arrays however are no values. So the error given by matlab is the following
??? Attempted to access dummy(9); index out of bounds because numel(dummy)=0.
Error in ==> GFCP at 29 funny=size(dummy(i));
How can I solve this? Is there really a need for an if statement? as to say if the array is empty go on to the next one
0 Kommentare
Antworten (1)
Walter Roberson
am 20 Mai 2013
You need to keep in mind that
size(dummy(i))
is going to return a vector, and that using 1:(a vector) is not going to give you what you want.
You also need to remember that after accessing
dummy = array{i};
then dummy will either be a regular array or a cell array (depending on what was stored there.) If it is regular array, such as an array of doubles, then dummy(i) is going to be either an error (because there are not at least "i" elements in the array) or else a single numeric value. size() of a single numeric value is [1 1], and so is not interesting. If dummy has become a cell array, then dummy(i) is going to be either an error (because there are not at least "i" elements in the cell array or else is going to be the size of a single cell, which again is going to be [1 1]. If dummy was a cell array, then size(dummy{i}) would be the size of what is stored at dummy(i) and would be of interest.
It is not clear why you would be proceeding "diagonally" in "array", taking the "i"'th element of "array" and then taking the "i'th" element of the result ?
0 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!