Consider Preallocating for speed
4 views (last 30 days)
Show older comments
uiimport ('standard.xls'); %cell array
pause(20)
for i=1:length(standard)
for j=1:13
if ischar(standard{i,j})==1 % si l'élement {i,j}
standard{i,j}= str2double (standard{i,j}); %line 6
end
end
end
B=cell2mat(standard);
Matlab says this for line 6:
The size of the indicated variable or array appears to be changing with each loop iteration. Commonly, this message appears because an array is growing by assignment or concatenation. Growing an array by assignment or concatenation can be expensive. For large arrays, MATLAB must allocate a new block of memory and copy the older array contents to the new array as it makes each assignment.
Programs that change the size of a variable in this way can spend most of their run time in this inefficient activity. There is also significant overhead in shrinking an array on each iteration or in changing the size of a variable on each iteration. In such cases, MATLAB must reallocate and copy the contents repeatedly.
Someone can help me ?
0 Comments
Answers (1)
Walter Roberson
on 12 May 2016
The warning is not relevant that this particular code. MATLAB is not noticing that you are "poofing" the variable named standard into existence will its full size and thinks that you are expanding the array as you go.
You can get around the warning (and improve your code) by using
datastruct = uiimport ('standard.xls'); %cell array
standard = datastruct.standard;
2 Comments
Walter Roberson
on 12 May 2016
You saved the data into Datastruct with a capital D when it should have been datastruct with a lowercase D.
You can "publish" in Word format; see http://www.mathworks.com/help/matlab/ref/publish.html#btbso84 . I have never tried that.
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!